1.4.4 • Published 6 years ago

jwt-express-login v1.4.4

Weekly downloads
2
License
ISC
Repository
-
Last release
6 years ago

jwt-express-login 1.3.0

This is an alpha-ver for user login with jwt , Mysql and Node.js.

Attention !!!

It's not a stable module with jwt login because we're testing every feature and util modules now.

And if you try to use jwt & passport to implement user's login ,

I recommend that you're supposed to do that by yourself.

Features

  • Integrating jwt / express / passport / passport local-strategy for Mysql
  • Customized cookie name
  • Using jwt encode / decode with express middleware

Installation

npm install jwt-express-login

Tp run the tests:

Sorry! It's nothing right now.

Documentation

Create a jwt-express-login instance.

const jwtExpressLogin = require("jwt-express-login");
const jwtHelper = new jwtExpressLogin({
    secret : {your-secret},
    options: {options-for-jwt},
    cookieName : {cookie-for-jwt},
    // dbPools : {your-mysql-pools}, [Deprecated]
    userQuerySqlPack : {
        sql : {your-searching-sql-code}
    }
    dbConfig : {your-mysql-config}
});

Example:

const jwtExpressLogin = require("jwt-express-login");
const jwtHelper = new jwtExpressLogin({
    secret : "test",
    options: {
        algorithm : "HS256",
        expiresIn : "1h"
    },
    cookieName : "_test_cookie",
    dbPools : mysql.createPool({MySqlDbConfig}),
    userQuerySqlPack : {
        "sql" : "SELECT * FROM members WHERE memberNo = ?;"
    }
});

API Reference

.tokenValidate(req,res,next)

Check JWT is valid or not. If it's invalid , the user will be redirected to '/' location.

Example:

// Using in express middleware
app.use(
    jwtHelper.tokenValidate,
    jwtHelper.tokenDecode,
    (req,res,next)=>{ // Do something }
);

.tokenDecode(req,res,next)

Decoding jwt into req.user info

Example:

// Using in express middleware
app.use(
    jwtHelper.tokenValidate,
    jwtHelper.tokenDecode,
    (req,res,next)=>{ // Do something }
);

.userValidation(req,res,next)

It inherits 'passport' middleware

Example:

// Implementation
this.userValidation = Passport.authenticate("local",{session:false});

// Using in express middleware
    router.post("/",
        jwtHelper.userValidation,
        jwtHelper.tokenEncode,
        (req,res,next)=>{ // Do something }
    );
);

.tokenEncode(req,res,next)

Encoding req.user info into jwt.

Example:

// Using in express middleware
router.post("/",
    jwtHelper.userValidation,
    jwtHelper.tokenEncode,
    (req,res,next)=>{ // Do something }
);

Others

I'll use mysql connection pools for initialization. (instance config) And this is my first time to develop npm module ~~~

1.4.4

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.5

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago