Actions of the JWT store.
login
- to be dispatched from login page (or, may be, login effects, if you have complex authorization)
loginSucceed
, loginErrored
- to indicate the result of the authorization.
loginAgain
- internal, is dispatched from the JwtGuard. Mostly the same, as login
,
but can have different effects (e.g. no navigation after loginAgainSucceed
).
loginAgainSucceed
, loginAgainErrored
- to indicate the result of the authorization,
triggered by the loginAgain
action.
loginAs
- to be dispatched by the authorized user, who wants to log in as another user. Contains the target user's UserId.
loginAsSucceed
, loginAsErrored
- to indicate the result of the authorization as another user.
logout
- to be dispatched by the authorized user. If there have been dispatched loginAs
before, JWTs
of the current user are destroyed (via calling JwtApi.logout), and JWTs and the UserInfo of the previous
user are restored from the store.
logoutSucceed
, logoutErrored
- to indicate the result of the logout.
stashUser
, unstashUser
, setUser
- internal, are used to implement restoration of the
previous user (if there have been dispatched loginAs
) during logout.
Generated using TypeDoc
Usage
Install package and it's dependencies.
Create the config JwtConfig. You can read recommendations in the description of each field.
Here is an example of the
JwtApi
implementation.This package plugs to the application NgRx store as a separate substore.
Import
JwtModule.forRoot(jwtConfig)
in your app. This will enable ngx-customapp-jwt store and provide services.Add types to the NgRx AppState.
Use jwtActions() function to create actions. Use created actions in your app.
Use jwtSelectors() function to create selectors. Use created selectors in your app.
Dispatch login({credentials}) to log in.
Dispatch logout({fromAllDevices}) to log out.
Handle the navigation after logging in.
Handle the navigation after logging out.
Display errors.
Add JwtInterceptor to the app.module providers, and every request will be sent with JWT in the header.
If you have configured JwtConfig.jwtGuard, add the JwtGuard to the routing, to handle paths, that require the user to be authorized.
You can also listen for the result of the authorization, triggered by the JwtGuard.