Try   HackMD

Cognito Auth with NextAuth.js

Create a Nextjs NextAuth project

git clone https://github.com/nextauthjs/next-auth-example.git
cd next-auth-example
npm i
cp .env.local.example .env.local

Add details for one or more providers (e.g. Google, Twitter, GitHub, Email, etc).
Using SQLite3 database.

Create Cognito pool

Followed instruction to create a user pool according to docs
https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-client-apps.html

Make sure that
Generate client secret is Disabled
(ALLOW_ADMIN_USER_PASSWORD_AUTH) is Enabled

Here's how the settings should l-ook like ,

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

and also set the scopes accoriding to nextauth docs
https://next-auth.js.org/providers/cognito

Add the provider in nextauth API and initialize the credentials

import Providers from `next-auth/providers`
...
providers: [
  Providers.Cognito({
    clientId: process.env.COGNITO_CLIENT_ID,
    domain: process.env.COGNITO_DOMAIN,
  })
]
...

Environment file

COGNITO_CLIENT_ID = <CLIENT_ID>
COGNITO_DOMAIN = <COGNTIO_DOMAIN_WITHOUT_HTTPS://>

Run your application

npm run dev

Solution by