Coder Social home page Coder Social logo

trulymittal / api-authentication-nodejs Goto Github PK

View Code? Open in Web Editor NEW
223.0 7.0 101.0 322 KB

API Authentication using JWT's (JSON Web Tokens). Plug n Play inside any app which requires authentication. NodeJs Express MongoDB & Redis.

JavaScript 97.50% Shell 2.50%
authentication jwt-authentication jwt jwt-token jwt-auth jwt-tokens api nodejs redis mongodb

api-authentication-nodejs's Issues

Why you used client.SET in this module? What is the Used

signRefreshToken: (userId) => {
return new Promise((resolve, reject) => {
const payload = {}
const secret = process.env.REFRESH_TOKEN_SECRET
const options = {
expiresIn: '1y',
issuer: 'pickurpage.com',
audience: userId,
}
JWT.sign(payload, secret, options, (err, token) => {
if (err) {
console.log(err.message)
// reject(err)
reject(createError.InternalServerError())
}

    client.SET(userId, token, 'EX', 365 * 24 * 60 * 60, (err, reply) => {
      if (err) {
        console.log(err.message)
        reject(createError.InternalServerError())
        return
      }
      resolve(token)
    })
  })
})

},

Uncaught Error - App crashes

@trulymittal
Hey, Thanks for the tutorial :)
But I've got a question
in User.model.js line: 30
Let's say an error will happen while hashing the password in try block
It will pass the error to the catch block and will be passed into next() function
But where would you handle that error ??
The error is not handled anywhere and it crashes the entire app

userSchema.pre('save', async function (next) {
  try {
    // something went wrong while hashing the password
    throw new Error('something went wrong')
  } catch (error) {
    // This will crash the app
    next(error)
  }
})

Redis connection lost and command aborted. It might have been processed

I have deployed API on another server and Redis on another server and connect each server for Redis but after some time like 10min or so if I try to access Redis data from API it's giving me AbortError: Redis connection lost and command aborted. It might have been processed but on local it's working fine.

ReplyError: ERR wrong number of arguments for 'set' command

I created separate file to test REDIS SET method but sending error of wrong argument.

const client = require('./config/redis_config');
client.SET(1, "test", 'EX', 3 * 24 * 60 * 60, (err, reply) => {
  if (err) {
    console.log(err);
    return;
  }
  return reply;
});

If I remove EX and TTL it works fine.

jwt

Sir how jwt identifies token is expired...?

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.