Login method is not implemented by jwt scheme - Oauth2


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)


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


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)”


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


+1, same one’s here.


Hey @jay-branchr! :wave:

Could you please share some code?



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);


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)


Thanks, @virk. I will try it out.