Auth Slice
Registered by AuthModule under the key auth, with the persistent
meta-reducer attached through AUTH_CONFIG_TOKEN:
StoreModule.forFeature('auth', authReducer, AUTH_CONFIG_TOKEN),
EffectsModule.forFeature([AuthEffects, UserStatusEffects]),
Shape
The slice is a combineReducers of three sub-states.
export interface AuthState {
auth: LoginState;
recoverPasswordRequest: RecoverPasswordRequestState;
newPasswordRequest: NewPasswordRequestState;
}
export interface LoginState {
loggedIn: boolean;
authToken: string;
user: Partial<User>;
isUserLoaded: boolean;
statusLoading: boolean;
dashboardStatusV2: SupplierDashboardStatusV2Dto;
}
export interface RecoverPasswordRequestState { isPending: boolean; requestSent: boolean; error: string; }
export interface NewPasswordRequestState { isPending: boolean; requestSend: boolean; error: string; }
|
There are two dashboard-status representations. |
Action types
src/app/core/auth/_actions/actions.enums.ts
| Member | String |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
noAction ('NO_ACTION') is a no-op used by init$ when there is no stored token.
Reducer behaviour
| Action | State change |
|---|---|
|
|
|
|
|
Store |
|
Set |
|
Replace |
|
|
|
Merge |
|
Set |
|
Replace |
|
Set |
|
|
|
|
Effects
src/app/core/auth/_effects/auth.effects.ts
| Effect | Trigger | Behaviour |
|---|---|---|
|
app start ( |
Reads |
|
|
Writes the token to |
|
|
Same as |
|
|
|
|
|
Skips when the user is already loaded; calls |
|
|
Re-fetches the user; dispatches |
|
|
|
|
|
→ |
|
|
→ |
|
|
|
|
|
|
|
|
|
|
|
|
UserStatusEffects (_effects/user-status.effects.ts) is registered alongside
and handles status-driven follow-up work.
|
|
Selectors
src/app/core/auth/_selectors/auth.selectors.ts
Session
| Selector | Returns |
|---|---|
|
The whole |
|
|
|
Session boolean |
|
Raw token string |
|
Whether the user object has arrived |
User
| Selector | Returns |
|---|---|
|
The |
|
|
|
|
|
|
|
|
|
|
|
|
Derived state
| Selector | Condition |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The hierarchical |
The permissions slice
Registered separately by ThemeModule under the key permissions, using
@ngrx/entity:
export interface State extends EntityState<Permission> {
isAllPermissionsLoaded: boolean;
}
export const adapter = createEntityAdapter<Permission>({ selectId: entity => entity.id });
Handled actions: allPermissionsRequested, allPermissionsLoaded (setAll),
permissionAdded (addOne), permissionRemoved (removeOne).