Login method is not implemented by jwt scheme - Oauth2


#1

Following the tutoiral here to implement auth via facebook credentials.

In the callback endpoint , the following line fails with an error message

await auth.login(user)

code:“E_INVALID_METHOD”

message:“E_INVALID_METHOD: login method is not implemented by jwt scheme\n> More details: https://err.sh/adonisjs/errors/E_INVALID_METHOD

name:“RuntimeException”

stack:“RuntimeException: E_INVALID_METHOD: login method is not implemented by jwt scheme\n> More details: https://err.sh/adonisjs/errors/E_INVALID_METHOD\n at Function.invoke (node_modules/@adonisjs/auth/node_modules/@adonisjs/generic-exceptions/src/RuntimeException.js:102:12)\n at JwtScheme.BaseScheme.(anonymous function) [as login] (node_modules/@adonisjs/auth/src/Schemes/Base.js:281:31)\n at LoginController.callback (app/Controllers/Http/LoginController.js:38:18)”

status:500

Can someone please let me know what’s going on wrong?


#2

+1, same one’s here.


#3

Hey @jay-branchr! :wave:

Could you please share some code?


#4

@romain.lanz

I followed the instructions given in the adonijs API documentation page. I noticed the callback is invoked. Below is the code i have in the callback method.

const fbUser = await ally.driver('facebook').fields(['email']).getUser();
/* a valid user is returned back. for testing purpose i hardcoded the email value */
const user = await User.findOrCreate(whereClause, {email:'xxx@yyy.com'}); 
await auth.login(user); // failed to authenticate

Tried using instead of login method above but no luck

await auth.loginViaId(user.user_id);


#5

There is nothing called login when you are using JWT. You generate a token and save it on client to authenticate requests.

What you need is auth.generate(user)


#6

Thanks, @virk. I will try it out.