Closed outluch closed 6 years ago
Yo. Actually it is kind of working. I just copy-pasted jwt scheme in auth config. And used it like auth.authenticator('sms').attempt(phone, uuid).
All tests pass excluding one, checking for error when attempt is failed. (eg wrong phone provided.
Look at my code: config/auth.js
authenticator: 'jwt', (default authenticator)
...
sms: {
serializer: 'lucid',
model: 'App/Models/Client',
scheme: 'jwt',
uid: 'phone',
password: 'uuid',
options: {
secret: 'self::app.appKey',
},
},
jwt: {
serializer: 'lucid',
model: 'App/Models/User',
scheme: 'jwt',
uid: 'email',
password: 'password',
options: {
secret: 'self::app.appKey',
},
},
And in controller:
async login({ request, response, auth }) {
const { phone, uuid } = request.all()
return auth.authenticator('sms').attempt(phone, uuid)
}
Despite I set my sms
authenticator, error handler just takes dafault config and generates error from its uid/password fields. I think it is error.
https://github.com/adonisjs/adonis-auth/blob/046610960bddfa20a6f256922fd458a0bda5e3d0/src/Exceptions/index.js#L44
Yup seems like a bug 🐛
Mind checking it from the develop branch of github and see if it reports with right errors?
Thanks. Will try a bit later, maybe weekend. Now quite busy.
I have 2 types of users and auth systems respectfully: client lgged in by phone number and unique device id, and operator, who work on orders, received from clients. Operators should log in with email/password or maybe username/password. More classical. How can I define two JWT schemes? Or I should write my own implementation for one of schemes? (or copy from adonis auth middleware?