Next-auth: OAUTH_CALLBACK_HANDLER_ERROR Error: Missing or invalid provider account

Created on 6 Jun 2020  路  11Comments  路  Source: nextauthjs/next-auth

I get this error whenever I try to log in:

OAUTH_CALLBACK_HANDLER_ERROR Error: Missing or invalid provider account

This is my [...nextauth].ts

import 'dotenv/config';
import NextAuth from 'next-auth';

const options = {
    site: process.env.SITE || 'http://localhost:3000',
    providers: [
        {
            id: "discord",
            name: "Discord",
            type: "oauth",
            version: '2.0',
            scope: 'identify',
            params: { grant_type: 'authorization_code' },
            accessTokenUrl: 'https://discord.com/api/oauth2/token',
            authorizationUrl:
                'https://discord.com/api/oauth2/authorize?response_type=code&prompt=consent',
            profileUrl: 'https://discord.com/api/users/@me',
            profile: (profile) => {
                console.log(profile);
                return {
                    name: profile.username,
                    image: `https://cdn.discord.com/avatars/${profile.id}/${profile.avatar}.png`,
                    email: `${profile.id}@loopback.neoney.xyz`
                }
            },
            clientId: process.env.CLIENT_ID,
            clientSecret: process.env.CLIENT_SECRET,
        },
    ],
    database: {
        type: process.env.DB_TYPE,
        host: process.env.DB_HOST,
        port: Number(process.env.DB_PORT),
        username: process.env.DB_USERNAME,
        password: process.env.DB_PASSWORD,
        database: process.env.DB_DATABASE,
        synchronize: process.env.DB_SYNCHRONIZE == "1",
        entityPrefix: process.env.DB_ENTITY_PREFIX
    }
};

export default (req, res) => NextAuth(req, res, options);

I have no idea how to fix it. I've tried re-creating the databases, deleted .next and node_modules, cleared my cookies. even created a new Discord account and tried with a different application (clientId and clientSecret). No change.

Most helpful comment

For anyone encountering this issue with cognito, fear not, @LoriKarikari has just added an in-built Cognito provider! Threw me a little, as I was half way through creating a custom provider :joy:

Cognito Provider docs are here: https://next-auth.js.org/providers/cognito

Thanks @iaincollins and @LoriKarikari for your great work :smile:

All 11 comments

Also, the console.log() in profile logs the whole profile:

{
  id: '718818651108671559',
  username: 'neoney2',
  avatar: null,
  discriminator: '3021',
  public_flags: 0,
  flags: 0,
  locale: 'en-US',
  mfa_enabled: false
}

We already have a built-in Discord provider that you can use. I think your provider config clashes because it has the same id as an existing (the built-in) one.

Yes, I know about that provider, this is the code from it copied and edited for my use. The point is, it worked, and it doesn't anymore. I've tried changing the id of the provider to no avail.

Does the built-in one still work?

OH, I think I know what happened. I must've updated the module by accident and it must've had a breaking change. It does work.

I'll close this.

Haha, no worries!

^ Thanks for posting the entire config BTW, it's really helpful when folks do that!

For anyone encountering this issue with cognito, fear not, @LoriKarikari has just added an in-built Cognito provider! Threw me a little, as I was half way through creating a custom provider :joy:

Cognito Provider docs are here: https://next-auth.js.org/providers/cognito

Thanks @iaincollins and @LoriKarikari for your great work :smile:

yw @adammanderson. If you are running into issues let us know. I was only able to test it with an AWS domain and not a custom one.

@adammanderson BTW build this hasn't gone out yet, but will do a release this evening with it and the new Battle.net provider @LoriKarikari has done :-)

(Am going to try and automate publishing when we do a release so we don't have to do this manually.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alex-cory picture alex-cory  路  3Comments

simonbbyrne picture simonbbyrne  路  3Comments

dmi3y picture dmi3y  路  3Comments

alephart picture alephart  路  3Comments

loonskai picture loonskai  路  3Comments