Giter Club home page Giter Club logo

nodeauthapp's Introduction

Node Authentication API

API for registering users with mongodb and authentication using a JWT (json web token). This app uses passport and passport-jwt and uses a JWT strategy

Version

1.0.0

Usage

npm install
npm start

Endpoints

POST /users/register
POST /users/authenticate   // Gives back a token
GET /users/profile         // Needs json web token to authorize

nodeauthapp's People

Contributors

azam2926 avatar bradtraversy avatar capitanbasa avatar rassl avatar stanleyeosakul 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

nodeauthapp's Issues

Horrible package.json

Man, i know... Those tutorials on your youtube channel,
just an example of app, just for design and so on.
But guys will get it as manual for further implementations.
And it is wrong way to teach people do things like that:

  "dependencies": {
    "express": "*",
    "mongoose": "*",
    "bcryptjs": "*",
    "cors": "*",
    "jsonwebtoken": "*",
    "body-parser": "*",
    "passport": "*",
    "passport-jwt": "*"
  },

These dependencies has updated (few of them with breaking changes) sins you've been accomplishing your app about year ago.
Be careful, be professional. Please!
Peace!

bcrypt illegal arguments issue

Error: Illegal arguments: undefined, string
at _async (C:\Users\OPERATIONS\Documents\nodeauthapp\node_modules\bcryptjs\dist\bcrypt.js:214:46)
at Object.bcrypt.hash (C:\Users\OPERATIONS\Documents\nodeauthapp\node_modules\bcryptjs\dist\bcrypt.js:220:13)
at bcrypt.genSalt (C:\Users\OPERATIONS\Documents\nodeauthapp\models\user.js:37:12)

Why do we need to prefix 'JWT ' to token?

Hello,

I was following your tutorial from youtube it works fine,
You explained it very well, thank you for that.
I just have a little query why do we need to prefix 'JWT ' to token while sending a response back.
By the way with prefixing 'JWT ' it works fine but as soon as I remove 'JWT ', it didn't work, I'm wondering why this is happening? any specific logical or syntactical reason?

Error: Illegal arguments: number, string

im having trouble with the comparePassword function,
i try to authenticate via Post and I get a error

Im using the latest npm package

module.exports.comparePassword = function(candidatePassword, hash, callback){ bcrypt.compare(candidatePassword, hash, (err, isMatch) => { if(err) throw err; callback(null, isMatch); }); }

Illegal arguments: number

user = new User({
name,
email,
avatar,
password
});

	// Encrypt password

	const salt = await bcrypt.getSalt(10);

	user.password = await bcrypt.hash(password, salt);

Error: Expected "payload" to be a plain object.

Hello brad,
I was following your tutorial from youtube, and while running authentication in postman Iam getting error that Error: Expected "payload" to be a plain object. at validate (/home/vijo/Music/MeanLearn/node_modules/jsonwebtoken/sign.js:34:11) at validatePayload (/home/vijo/Music/MeanLearn/node_modules/jsonwebtoken/sign.js:56:10) at Object.module.exports [as sign] (/home/vijo/Music/MeanLearn/node_modules/jsonwebtoken/sign.js:108:7) at User.comparePassword (/home/vijo/Music/MeanLearn/routes/users.js:41:33) at bcrypt.compare (/home/vijo/Music/MeanLearn/models/user.js:46:9) at /home/vijo/Music/MeanLearn/node_modules/bcryptjs/dist/bcrypt.js:297:21 at /home/vijo/Music/MeanLearn/node_modules/bcryptjs/dist/bcrypt.js:1353:21 at Immediate.next [as _onImmediate] (/home/vijo/Music/MeanLearn/node_modules/bcryptjs/dist/bcrypt.js:1233:21) at runCallback (timers.js:789:20) at tryOnImmediate (timers.js:751:5) at processImmediate [as _immediateCallback] (timers.js:722:5)

Please help me to resolve this

passport.js

`const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
const User = require('../models/user');
const config = require('../config/database');

module.exports = function(passport){
let opts = {};
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme("jwt");
opts.secretOrKey = config.secret;
passport.use(new JwtStrategy(opts, (jwt_payload, done) => {
User.getUserById(jwt_payload.data._id, (err, user) => {
if(err){
return done(err, false);
}

  if(user){
    return done(null, user);
  } else {
    return done(null, false);
  }
});
}));
}`

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.