GithubHelp home page GithubHelp logo

bezkoder / node-js-jwt-auth-mongodb Goto Github PK

View Code? Open in Web Editor NEW
336.0 12.0 185.0 59 KB

Node.js + MongoDB: User Authentication & Authorization with JWT

JavaScript 100.00%
jwt node-mongodb node nodejs node-js mongodb mongoose authentication authorization rest-api

node-js-jwt-auth-mongodb's Introduction

Node.js MongoDB โ€“ User Authentication & Authorization example with JWT & Mongoose

User Registration, User Login and Authorization process.

The diagram shows flow of how we implement User Registration, User Login and Authorization process.

jwt-token-authentication-node-js-example-flow

For more detail, please visit:

Node.js + MongoDB: User Authentication & Authorization with JWT

You may need to implement Refresh Token:

jwt-refresh-token-node-js-example-flow

Node.js JWT Refresh Token with MongoDB example

Working with Front-end:

Vue

Angular 8 / Angular 10 / Angular 11 / Angular 12 / Angular 13

React / React + Redux

More Practice:

Node.js, Express & MongoDb: Build a CRUD Rest Api example

Server side Pagination in Node.js with MongoDB and Mongoose

Node.js Express File Upload Rest API example

Associations:

MongoDB One-to-One relationship tutorial with Mongoose examples

MongoDB One-to-Many Relationship tutorial with Mongoose examples

MongoDB Many-to-Many Relationship with Mongoose examples

Fullstack:

Vue.js + Node.js + Express + MongoDB example

Angular 8 + Node.js + Express + MongoDB example

Angular 10 + Node.js + Express + MongoDB example

Angular 11 + Node.js + Express + MongoDB example

Angular 12 + Node.js + Express + MongoDB example

Angular 13 + Node.js + Express + MongoDB example

Angular 14 + Node.js + Express + MongoDB example

Angular 15 + Node.js + Express + MongoDB example

Angular 16 + Node.js + Express + MongoDB example

React + Node.js + Express + MongoDB example

Integration on same Server/Port:

Integrate Vue with Node.js Express

Integrate Angular with Node.js Express

Integrate React with Node.js Express

Project setup

npm install

Run

node server.js

node-js-jwt-auth-mongodb's People

Contributors

tienbku avatar

Stargazers

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

Watchers

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

node-js-jwt-auth-mongodb's Issues

SyntaxError: Unexpected token a in JSON at position 69

ym@home node-js-jwt-auth-mongodb % node server.js
Server is running on port 8080.
Successfully connect to MongoDB.
SyntaxError: Unexpected token a in JSON at position 69
at JSON.parse ()
at parse (/Users/ym/NonDropBox/projects/bezkoder/node-js-jwt-auth-mongodb/node_modules/body-parser/lib/types/json.js:89:19)
at /Users/ym/NonDropBox/projects/bezkoder/node-js-jwt-auth-mongodb/node_modules/body-parser/lib/read.js:121:18
at invokeCallback (/Users/ym/NonDropBox/projects/bezkoder/node-js-jwt-auth-mongodb/node_modules/raw-body/index.js:224:16)
at done (/Users/ym/NonDropBox/projects/bezkoder/node-js-jwt-auth-mongodb/node_modules/raw-body/index.js:213:7)
at IncomingMessage.onEnd (/Users/ym/NonDropBox/projects/bezkoder/node-js-jwt-auth-mongodb/node_modules/raw-body/index.js:273:7)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21

getting a bcrypt error

I forked your code and ran npm install. Im running into this issue: Error: Illegal arguments: undefined, string

(method:Post) localhost:8080/api/auth/signup

Error: Illegal arguments: undefined, string
at Object.bcrypt.hashSync (/Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/node_modules/bcryptjs/dist/bcrypt.js:189:19)
at exports.signup (/Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/app/controllers/auth.controller.js:13:22)
at Layer.handle [as handle_request] (/Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/node_modules/express/lib/router/route.js:137:13)
at checkRolesExisted (/Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/app/middlewares/verifySignUp.js:51:3)
at Layer.handle [as handle_request] (/Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/node_modules/express/lib/router/route.js:137:13)
at /Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/app/middlewares/verifySignUp.js:34:7
at /Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/node_modules/mongoose/lib/model.js:4915:16
at /Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/node_modules/mongoose/lib/helpers/promiseOrCallback.js:24:16
at /Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/node_modules/mongoose/lib/model.js:4938:21
at /Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/node_modules/mongoose/lib/query.js:4380:11
at /Users/lordknighton/Desktop/node-js-jwt-auth-mongodb/node_modules/kareem/index.js:135:16
at processTicksAndRejections (internal/process/task_queues.js:79:11)

License?

Could you please add a License?

Thank you.

Getting 500 Error when trying to register new user into the app

I have given the below things in the body

{
"username": "modera",
"email": "[email protected]",
"password": "12345678",
"roles": ["user", "moderator"]
}

Below is the exception error i am getting

Error: Illegal arguments: undefined, string
at Object.bcrypt.hashSync (/home/labadmin/lab/node-js-jwt-auth-mongodb-master/node_modules/bcryptjs/dist/bcrypt.js:189:19)
at exports.signup (/home/labadmin/lab/node-js-jwt-auth-mongodb-master/app/controllers/auth.controller.js:13:22)
at Layer.handle [as handle_request] (/home/labadmin/lab/node-js-jwt-auth-mongodb-master/node_modules/express/lib/router/layer.js:95:5)
at next (/home/labadmin/lab/node-js-jwt-auth-mongodb-master/node_modules/express/lib/router/route.js:137:13)
at checkRolesExisted (/home/labadmin/lab/node-js-jwt-auth-mongodb-master/app/middlewares/verifySignUp.js:51:3)
at Layer.handle [as handle_request] (/home/labadmin/lab/node-js-jwt-auth-mongodb-master/node_modules/express/lib/router/layer.js:95:5)
at next (/home/labadmin/lab/node-js-jwt-auth-mongodb-master/node_modules/express/lib/router/route.js:137:13)
at User.findOne.exec (/home/labadmin/lab/node-js-jwt-auth-mongodb-master/app/middlewares/verifySignUp.js:34:7)
at immediate (/home/labadmin/lab/node-js-jwt-auth-mongodb-master/node_modules/mongoose/lib/model.js:5065:18)
at process._tickCallback (internal/process/next_tick.js:61:11)

verifyToken is not defined

I've copied and pasted the code, but getting the following error:

verifyToken = function verifyToken(req, res, next) { ^ ReferenceError: verifyToken is not defined

this is in the file authJwt.js, line 12.

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.