Skip to content

g3org3/express-auth-jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

42 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš“๐Ÿช express-auth-jwt

Getting Started

You will need Node >= 7 installed. How do I install node? click here to find out about nvm

Installation

# install module
npm install express-auth-jwt

# install deps
npm install jsonwebtoken body-parser cookie-parser cookie-session

# all in one command
npm install express-auth-jwt jsonwebtoken body-parser cookie-parser cookie-session

Example

see examples

Generated Endpoints

Method Endpoint Body Params Description
GET /auth - simple check to verify the setup was succesful
GET /auth/me - returns the user's profile
GET /auth/logout - removes the session
POST /auth/token { _id, password } to request a new JWT token and creates the session
  • GET /auth/login?token=JWT

Default config

const defaultConfig = {
  database: {
    getUser: () =>
      Promise.reject(
        new Error('Function UserFindOne, not specified in the express-jwt-util(config)')
      ),
    findQuery: { username: true },
    userIdField: '_id',
    comparePasswords: (dbPassword, requestPassword) => dbPassword === requestPassword,
  },
  jwt: {
    secret: 'sekret',
    // ---------------- hr | min | sec | mili
    timeToExpire: 1 * 60 * 60 * 1000,
  },
  cookie: {
    name: 'EAU_cid',
  },
  session: {
    resave: false,
    secret: 'keyboard cat',
    saveUninitialized: true,
    cookie: {
      httpOnly: true,
      maxAge: 3600,
    },
  },
  messages: {
    tokenNotFound: 'No token provided.',
    tokenExpired: 'The session has expired.',
    failToAuthenticate: 'Could not authenticate.',
    userNotFound: 'The user is not valid.',
    wrongPassword: 'The password is incorrect.',
    loginSucess: 'Enjoy your token!',
    logout: 'logout',
  },
};

FAQs

// if you want to use email or username
// you need to modify on the initial config
const config = {
  database: {
    userIdField: โ€˜emailโ€™
  }
}

......expressAuthJWT(config)

Contributors

About

๐Ÿš“๐Ÿช Express auth utils JWT, session

Resources

License

Stars

Watchers

Forks

Packages

No packages published