Example application using next-iron-session-with-JWT-authentication
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 andswr
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 the example live on Vercel:
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
- Clone this project. then:
npm run install
-
Set up your authentication index keys according to your server response as environment variables (.env).
-
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).