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.



I get the following error message when i tried to redirect to a protected URL after using auth.generate(user)

E_INVALID_JWT_TOKEN: jwt must be provided.

request.request.headers[‘authorization’] = bearer ${fbUser.token};


While debugging I observed that

line #378 const token = this.getAuthHeader() in jwt.js file always returns a null. For some reason the authorization token set in the header is not available. I tried setting request.headers['authorization'] too, but no luck.


Why are you setting the header on the server? The client who is making the request sends the token to the server



I’m using JWT auth mechanism in my project and one of the login source is to login via facebook credentials.

Below are the steps I’ve implemented

  1. Authentication via from facebook API . The Ally-Facebook API works fine.

  2. As you recommended I used auth.generate(user) to generate the token for the authenticated user.

  3. When i try to redirect to a protected url - response.redirect(’/index’).

    • A simple redirect without the header setting threw an E_INVALID_JWT_TOKEN: jwt must be provided. error.
    • To solve this error I tried adding the authorization in the header
  4. Routes.js has the following configuration

     .get('index', 'UserController.index')
     .middleware('auth') ```
  5. kernel.js has the following middleware configured

const globalMiddleware = [

```const namedMiddleware = {
auth: 'Adonis/Middleware/Auth'


Is there anything wrong in my flow, please let me know.


You can try this solutions if you want

const FirebaseAdmin = use('Perafan/FirebaseAdmin')

await FirebaseAdmin.auth()
      .verifyIdToken(token)  // token id from firebase
      .then(async userFirebase => {
        console.log('Token valid.')

        const requestHeaders = request.headers()

        let user = await User.findByOrFail('username', userFirebase.uid)
        let userAuth = await auth.generate(user)

        requestHeaders.authorization = 'Bearer ' + userAuth.token
      .catch(function(error) {
        throw error
await next()