Simple and fast setup JWT Authentication in the Angular app.

npm i @dekh/ngx-jwt-auth
  • authApiService: Type<BaseAuthApiService> — A class that implements BaseAuthApiService and makes requests to the server, our previously created auth-api.service.ts class.
  • tokenStorage: Type<BaseTokenStorage> — Storage of regular tokens (not authorization ones).
  • authTokenStorage: Type<BaseTokenStorage> — Storage of authorization tokens.

Bonus

List of predefined Token Storages

  • CookiesTokenStorage — abstraction over cookies, saves tokens in cookies;
  • LocalStorageTokenStorage — abstraction over localStorage, stores tokens in localStorage;
  • SessionStorageTokenStorage — abstraction over sessionStorage, saves tokens in sessionStorage;
  • InMemoryTokenStorage — saves tokens in the application memory, there are some drawbacks, when using this storage for authorization tokens, after reloading the page, a request will be made to update the access token (for SPA applications this is not critical), but the most secure storage for authorization tokens;

Creating your own Token Storage

Changing token storage at runtime

P.S.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store