An authentication and authorization backend server build using Express in NodeJS and uses MongoDB to store user dabtabase.
- user can signup
- user can login and get their JWT token to authorized themselves
- verify JWT token (authozrization)
- uses Adapter pattern to switched between storage and database
- build on MVC architecture
- can be scale to microservice architecture easily
- can be used by any other service to authenticate and for authorization
- hosted on heroku platform
- clone the repository
git clone https://github.com/altafshaikh/nodejs-authentication-backend.git
- add a
.env
file inside the root folder
PORT=3001
JWT_SECRET=any random string
LOCAL_DB_URL=your local mongo url
DATABASE_URL=your_atlas_db_url(keep this empty is ur not provoding any url)
DEBUG=true // set true to use local db and false to use atlas
STORAGE=mongodb // to switch file storage or mongodb database (mongodb | file)
Sample for local
PORT=3001
JWT_SECRET=RawSshCaaafuiokld
LOCAL_DB_URL=mongodb://127.0.0.1:27017/auth
DATABASE_URL=
DEBUG=true // set true to use local db and false to use atlas
STORAGE=mongodb
/signup : (method:post) - create user accout
/login : (method:post) - get jwt token and authenticate yourself using the creds (email,password)
/auth : to restrict the user from accessing the resources on route /blogs so send token in authorization header as bearer token
To Host the Project I had used Heroku Platform. To learn more refer this gist
- mongoose quick start
- mongoDB documentation reference
- uniquid to generate unique ids
- npm express
- CORS module to talk between cross-origin resources
- jwt intoduction
- Adapter Design Pattern
- Altaf Shaikh - work by - altafshaikh
This project is licensed under the MIT License - see the LICENSE.md file for details