0.0.3 • Published 10 months ago

@juunini/jwt-auth-server v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

JWT Auth for server-side

Usage

Init

// const { default: JWTAuth } = require('@juunini/jwt-auth-server');
import JWTAuth from '@juunini/jwt-auth-server';

const jwtAuth = new JWTAuth({
  alg: 'HS256', // default: HS256
  secret: 'your-awesome-secret',
  accessToken: {
    expire: '5m', // recommand 5m ~ 30m (default: 5m)
  },
  refreshToken: {
    expire: '1d', // recommand 1d ~ 7d (default: 1d)
  },
  redis: { // optional, but recommand
    host: '127.0.0.1',
    port: 6379,
    db: 0, // optional
    username: 'user', // optional
    password: 'pass', // optional
  },
  redisCluster: { // optional, if you use redis cluster
    startupNodes: [ ... ],
    options: { ... }, // optional
  }
});

Login

jwtAuth.login({ ...payload });

Verify

// if you not set redis connection
jwtAuth.verify(accessToken);

// if you set redis connection
await jwtAuth.verify(refreshToken);

Refresh

const newToken = await jwtAuth.refresh({ accessToken, refreshToken });
// newToken.accessToken
// newToken.refreshToken

Logout

If you set redis connection, logout method will create blacklist old tokens.

await jwtAuth.logout({
  accessToken,
  refreshToken,
});
0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago

0.0.1-alpha.1

10 months ago