npm.io
5.0.2 • Published 5 years ago

@ctng/auth-jwt-ls

Licence
Version
5.0.2
Deps
1
Size
49 kB
Vulns
0
Weekly
0
Stars
2

Auth-Jwt-Ls

This is a library for handling Json Web Tokens by using the jwt-decode library and local storage to persist the token. Additionally it checks if the token is expired.

Usage

Just inject the JwtLocalStorageService and

  • set/get tokens
  • get token's expiration date
  • check if token is expired
  • remove token from local storage

Custom config

By default JwtLocalStorageService assumes that the token object has an exp property with time value in seconds.

If a the token has a different structure or format, a custom JwtConfig can be provided:

{
  provide: JWT_CONFIG,
  useValue: {
    getExpirationDate: (token: CustomToken) => {
      return new Date(token.customExpDate);
    },
  },
},