Skip to content

adherb/next-auth-express-mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 

Repository files navigation

πŸš€ Next-Auth with Express, MongoDB, and TailwindCSS

This repository showcases a full-stack authentication solution, combining:

  • Next.js for frontend development, styled with the aesthetics of TailwindCSS. 🎨
  • Express.js for backend API routes and logic. πŸ–₯️
  • MongoDB as the go-to database. πŸ—„οΈ

πŸ› Architecture

  • Frontend: Combining Next.js, TailwindCSS, and the next-auth package, we offer a seamless user experience and session management.

  • Backend: Express.js provides our API routes handling user registration, login, JWT creation, and validation. 🎩

  • Database: MongoDB ensures secure storage of user details. Passwords are stored securely, hashed with bcrypt. πŸ”

πŸ”’ How Authentication Works

  1. User Registration:

    • Input email and password. πŸ“§
    • Passwords are hashed using bcrypt before storage.
    • Successful registration redirects to the login page. πŸ‘£
  2. User Login:

    • Provide your email and password. 🌐
    • Express.js verifies credentials against MongoDB.
    • On successful authentication, receive a JWT as an HttpOnly cookie. πŸͺ
  3. Authenticated Requests:

    • For authenticated requests, the browser sends the JWT cookie automatically. 🌍
    • Express verifies the JWT on each request.
  4. Session Management on Frontend:

    • next-auth manages user sessions on the frontend. 🌈
    • Use utilities like useSession to render content based on authentication state. πŸ“Š
  5. Logout:

    • Logout to end the session. πŸ”š
    • The JWT cookie is cleared. πŸ”„

πŸ’» Local Setup

  1. Clone the Repo:

    git clone https://github.com/adherb/next-auth-express-mongo.git
  2. Install Dependencies:

    yarn install
  3. Environment Variables:

    • Rename .env.example to .env. πŸ”§
    • Update with required environment variables.
  4. Run the Development Server:

    yarn dev
  5. Visit http://localhost:3000 in your browser. 🌍

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published