nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
24.29k stars 3.39k forks source link

Cognito Provider Documentation Update #9654

Open howardkitto opened 8 months ago

howardkitto commented 8 months ago

What is the improvement or update you wish to see?

The docs here: https://next-auth.js.org/providers/cognito

Refer to these settings:

image

The aws UI must have changed - it took me a while to find these settings - they are in appclient / hosted UI and before you can set them you must set up a cognito domain. They look like this now:

Screenshot 2024-01-16 at 12 28 14

Wasted quite a while figuring that out!

It would also be great to include the cloudformation template for this

Is there any context that might help us understand?

I'm trying to create a secure custom authflow for my AWS SAM backend

Does the docs page already exist? Please link to it.

https://next-auth.js.org/providers/cognito

dango0812 commented 8 months ago

I wrrited the blog post and sample code. take a look https://dev.to/dango0812/nextauth-with-aws-cognito-email-google-sign-in-5ef6

kylemh commented 7 months ago

@dango0812 is your setup compatible with edge middleware or is Cognito in general not compatible?

dango0812 commented 6 months ago

@dango0812 is your setup compatible with edge middleware or is Cognito in general not compatible?

Middleware and Cognito are unrelated, could you please provide more details or clarification on the topic you want to inquire about?

kylemh commented 6 months ago

I was looking at the repository linked at the end of the blog post and found no examples surrounding auth-gating with middleware.

dango0812 commented 5 months ago

@kylemh I apologize for contacting you late. To handle authentication and redirection after verification in the middleware, you can access it through 'getToken' and process accordingly.

sample code

import { getToken } from "next-auth/jwt";
const session = await getToken({ req, secret: process.env.NEXTAUTH_SECRET });
// your session object key check and redirect

if ...
return NextResponse.redirect(new URL(""))