Amplify js cannot authenticate a user with "responseType: code" in Next.js

149 Views Asked by At

I'm using amplify version 5(v5.2.5) to authenticate a user in Cognito user pool with hosted UI and idp. When I launch the Hosted UI address, redirect success to signIn URL and I have a code(example: localhost:3000/?code=abcd-xyzt-...) but the session is not stored.

Any one know the reason? Or that is an issue of Next.js? This is my config:

Amplify.configure({
    Auth:
        {
            region: process.env.COGNITO_REGION,
            userPoolId: process.env.COGNITO_USER_POOL_ID,
            userPoolWebClientId: process.env.COGNITO_CLIENT_ID,
            mandatorySignIn: false,
            oauth: {
                domain: process.env.COGNITO_DOMAIN,
                scopes: ['email', 'openid'],
                redirectSignIn: process.env.APP_SIGN_IN_URL,
                responseType: 'code',
        },
    }
});

I debug with Hub and get the error: event: "signIn_failure", message: "Username and Pool information are required.". But when use responseType: 'token', it's working normally. What's even stranger is that when I used the same configuration(same user pool, same idp, anything is the same) with two other applications using Nuxt.js and Vue.js, it worked fine with both "token" and "code" response type.

0

There are 0 best solutions below