Giter Site home page Giter Site logo

next-auth-ioredis-adapter-example's Introduction

An example of using Next Auth with ioredis library to save user data into Redis Server with IORedisAdapter.

IORedisAdapter saves data with Hash data structure instead of JSON.stringify to simplify the management of user data.

For example, a role field ("admin" | "moderator" | "user") in User object in [...nextauth].ts

Getting Started

  1. Create an .env file work the following content:

    REDIS_URL="redis://....."
    GITHUB_CLIENT_ID = ""
    GITHUB_CLIENT_SECRET = ""
    NEXTAUTH_URL="http://localhost:3000"
    NEXTAUTH_SECRET="SOME_SECRET"
    
  2. Run the server

    npm run dev
    # or
    yarn dev

next-auth-ioredis-adapter-example's People

Contributors

quanhua92 avatar saderyal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

next-auth-ioredis-adapter-example's Issues

Security Issue using emails

Hi, I recently discovered this adapter for Redis, which I found really great and easy to implement.
So, first of all, I want to thank you for your job :)

But, I found a really important vulnerability issue in verification-token based authentications (Email authentications).
Basically, I've seen that your useVerificationToken function simply checks if there is a verification token with the specified email, but it doesn't check if the token is valid or not.

This means that, for example, the user [email protected] can request an email to sign in, and a verification link will be sent in his mailbox. Everything, for now, it's Ok.
But then a potential hacker who knows that [email protected] is trying to authenticate, can simply access to his profile with a random token, because in the adapter there is not a token validation. So, the hacker can go to this URL:

http://localhost:3000/api/auth/callback/email?callbackUrl=http://localhost:3000&token=INVALID_RANDOM_TOKEN&[email protected]

And he will be successfully authenticated!

I resolved this issue by modifying the useVerificationToken function like this:

async useVerificationToken(verificationToken) {
    const id = verificationToken.identifier;
    const token = await getVerificationToken(id);
    if (!token || verificationToken.token !== token.token)
      return null;
    await deleteVerificationToken(id);
    return token;
 },

Hope this helps! ๐Ÿ‘๐Ÿป

Great Job with the adapter anyway! ๐Ÿฅณ

Fail on login

Hi,

Thanks for your great work.

When I try your library, I just copy and paste your example, everything is setup same as your code, but then it keeps on showing the login page:

Screenshot 2023-03-22 at 10 34 44 PM

Click the login button it just refresh the page and show again.

My environment:

  • node: v16.18.0
  • next: 13.2.4
  • next-auth: 4.20.1
  • ioredis: 5.3.1

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.