1

I have a Next.js application that calls AWS functions. I want to add a login functionality to it though using a JWT token. I don't know how to do this. I want to publish the app as a static website so I don't want to have an express server.

I have looked at a whole lot of the solutions which all using a server to handle the JWT stuff. I would like to handle all of the authentication in an AWS Lambda function and then send through a JWT token to the Next.js app. Is this possible?

1 Answer 1

1

I would suggest you to have a look at AWS Cognito. Cognito User Pool is user directory with signin, signup, lost password, email verification and MFA flows and API. You can also federate identities from other Identity providers, such as Amazon, Google, Facebook, SAML or any OpenID compatible providers.

To make it easier to provision Cognito and use it in your client-side React App, have a look at the Amplify command line tool and SDK.

Adding Cognito to your project is as easy as : amplify add auth && amplify push Amplify comes with a builtin user interface to implement the signin and signup flows, but of course you can choose to build your own.

The authentication part of Amplify documentation is available at https://aws-amplify.github.io/docs/js/authentication

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. There are problems using Amplify with SSR. Is there another way to do it or to generate the JWT in the AWS lambda function and send it through to the client?
well, your original question mentioned "static web hosting", which seems contradictory to SSR :-) According to github.com/aws-amplify/amplify-js/issues/1613 the graphql part of amplify is not compatible with next.js, but the auth part is

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.