Giter Club home page Giter Club logo

modulessoft / next-js-with-iron-session-and-jwt-authentication Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 280 KB

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.

Home Page: https://next-js-with-iron-session-and-jwt-authentication.vercel.app/

JavaScript 100.00%
jwt-authentication swr reactjs nextjs graphql-client js json api api-client encryption

next-js-with-iron-session-and-jwt-authentication's Introduction


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).

next-js-with-iron-session-and-jwt-authentication's People

Contributors

modulessoft avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.