How to make a registration/login system with Query builder

Hello,
I’d like to ask you a question.
Being a beginner on this framework, I would like to know how to make a login and registration system easily with Query Builder.

Do you have any sources to provide me with a story that I understand how it works?
Thanks,

1 Like

Hi :wave:,
You can use Adonis Authentication (auth)

Example login :

/* Test login with credentials */
try {
  await auth.attempt(<uid>, <password>) //uid -> go to config/auth.js
} catch (error) {
  response.send('Bad credentials')
}

^ doc

/* Test if logged */
try {
  await auth.check()
} catch (error) {
  response.send('You are not logged in')
}

^ doc

Get auth object (from context) :

async login ({ auth, request }) {
    const { email, password } = request.all()
    await auth.attempt(email, password)

    return 'Logged in successfully'
  }

^ doc

2 Likes