Implementation auth for jwt


hi dears, i’d like if some body have some project of provider for generate the controller for auth, I do it and insert in my fork, but It was not accepted, then I think in make a provider or command line for generate it like in laravel

my fork



I recommend using Adonis persona. This can work with traditional session auth and with JWT too



Persona seems very cool. When I finally have it working (and my head is no longer bloody from beating it on my keyboard) I’m going to write up tutorial with all the things we’re all going to have to do to use it.


1 Like


Looking forward to your tutorial!



Hi! I use Adonisjs in “api only” mode with vuejs frontend. Is persona good for this case? And how to use JWT with it?



Hi Xia!

I use Adonis API only for backend and Nuxt for frontend as two separate apps (not AdoNuxt)

Works well with Persona and JWT. All I had to do was to change login little bit.

Persona Doc states under what it does not do:
3. Does not create sessions or generate JWT tokens.

So you have to generate JWT on your own after login attempt

// Let Persona handle login attempt
async login ({ request, auth }) {
  const payload = request.only(['uid', 'password'])
  // Throws error if invalid payload
  const user = await Persona.verify(payload) 
  // If login is OK, then generate token
  return auth.generate(user)

auth.generate() doc

Other way is to roll your own login

// Let auth handle login attempt
async login ({ request, auth }) {
  let { uid, password } = request.all()
  return auth.attempt(uid, password)

auth.attempt() doc

1 Like


Did you succeed to send emails with Persona @McSneaky ?



Hi @begueradj

I started implementing Persona ~30 minutes ago.

But looking at events Persona emits I think I can send email template to Mailgun to send it out actually

Have not tested so far, but here is my idea:

Create new event listener:
adonis make:listener User

Then inside generated file will write something like this:

const Mail = use('Mail')

Event.on('user::created', async (user) => {
  await Mail.send('emails.welcome', user.toJSON(), (message) => {
        .subject('Welcome to yardstick')
1 Like