Skip to content

Next.js implementation of a secure authentication system using signed and encrypted cookies for session data storage, utilizing JS next-iron-session, SWR, and JsonWebToken(JWT) libraries.

Notifications You must be signed in to change notification settings

ModulesSoft/next-js-with-iron-session-and-JWT-authentication

Repository files navigation


Online demo at https://next-js-with-iron-session-and-jwt-authentication.vercel.app/ 👀

You can use any username & password credentials since sample data will be returned by default.


This example creates an authentication system that uses a signed and encrypted cookie to store session data with JWT. It relies on next-iron-session, SWR and JsonWebToken.

It uses current best practices for authentication in the Next.js ecosystem.

On the next-iron-session repository (https://github.com/majhoolsoft/next-js-with-iron-session-and-JWT-authentication) you'll find:

Features:

  • Static Generation (SG), recommended example
  • Server-side Rendering (SSR) example in case you need it
  • Logged in status synchronized between browser windows/tabs using useUser hook and swr module
  • Layout based on the user's logged-in/out status
  • Session data is signed and encrypted in a cookie
  • Express / Connect middlewares
  • Multiple encryption keys (passwords) to allow for seamless updates or just password rotation

next-iron-session-with-JWT-Auth now supports:

  • JWT authentication

Preview

Preview the example live on Vercel:

Open in Vercel

Deploy your own

How to deploy with Graphql API.

This package comes with 2 sample data files which can be found in /lib.

sampleData.json is an example of access response from server, sampleData2.json is an example of refreshed access token

How to use

  1. Clone this project. then:
npm run install
  1. Set up your authentication index keys according to your server response as environment variables (.env).

  2. Write your own authentication request in /lib/authenticate.js and refresh access token request in /lib/refreshToken.js

Deploy it to the cloud with Vercel (Documentation).

About

Next.js implementation of a secure authentication system using signed and encrypted cookies for session data storage, utilizing JS next-iron-session, SWR, and JsonWebToken(JWT) libraries.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published