ngx-token-manager
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

NgxTokenManager

Small Angular service to easily manage tokens (like JWT) asynchronously in the browser without the use of localStorage.

Usage

Install

npm install ngx-token-manager

Provide NgxTokenModule in your app.module.ts file

import { NgxTokenModule } from "ngx-token-manager";

@NgModule({
  bootstrap: [AppComponent],
  imports: [
    // ...
    NgxTokenModule,
  ],
})
export class AppModule {}

Inject and use NgxTokenManager

constructor(private $token: NgxTokenManager<YourTokenModel>) {
  // get status of the token
  this.$token.getStatus().subscribe(status => {
    switch (status) {
      case TokenStatus.NONE: // there is no token
      case TokenStatus.EXPIRED: // token already expired
      case TokenStatus.UNEXPIRED: // token exists and hasn't expired
    }
  })
}

All Methods

  setKey(key: string): void
  getStatus(): Observable<TokenStatus>
  isExpired(): Observable<boolean>
  setToken(token: string): Observable<Date>
  getPayload(): Observable<YourTokenModel>
  delete(): Observable<void>
  changes$: Observable<YourTokenModel>

Readme

Keywords

none

Package Sidebar

Install

npm i ngx-token-manager

Weekly Downloads

56

Version

1.1.0

License

none

Unpacked Size

41.9 kB

Total Files

14

Last publish

Collaborators

  • enesien