1.1.0 • Published 2 years ago

ngx-token-manager v1.1.0

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

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>
1.1.0

2 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago