Code Monkey home page Code Monkey logo

login-registration-example's Introduction

a Node.js Express Login and Registration Rest API example that supports JWT (JSONWebToken) and works with MongoDB database using Mongoose ODM

Appropriate Flow for User Login and Registration with JWT Authentication Node.js Express Architecture with CORS, Authentication & Authorization middlewares & Sequelize How to configure Express routes to work with JWT How to define Data Models and association for Authentication and Authorization Way to use Mongoose ODM to interact with MongoDB Database

Methods Urls Actions POST /api/auth/signup signup new account POST /api/auth/signin login an account POST /api/auth/signout logout the account GET /api/test/all retrieve public content GET /api/test/user access User’s content GET /api/test/mod access Moderator’s content GET /api/test/admin access Admin’s content

Flow for login and Registration

Node.js Express Login with MongoDB Architecture

– config

configure MongoDB database configure Auth Key

– routes

auth.routes.js: POST signup, signin & signout user.routes.js: GET public & protected resources

– middlewares

verifySignUp.js: check duplicate Username or Email authJwt.js: verify Token, check User roles in database

– controllers

auth.controller.js: handle signup, signin & signout actions user.controller.js: return public & protected content

– models for Mongoose Models

user.model.js role.model.js

– server.js: import and initialize necessary modules and routes, listen for connections.

login-registration-example's People

Contributors

jchen985 avatar

Watchers

 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.