]> juplo.de Git - demos/angular/stored-login/commitdiff
fix: `token` / `error` are cleared correcly on error / success
authorKai Moritz <kai@juplo.de>
Mon, 15 Sep 2025 19:33:38 +0000 (21:33 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 15 Sep 2025 20:42:44 +0000 (22:42 +0200)
* also added a delay to make the disabling of the form visible

src/app/services/auth.service.ts
src/app/store/login.reducers.ts

index 3b4d86ae758566a3d9ac460377bd4bbd5e28b4c8..9c39495755de1bd954b8328108af0afff8e3e1c1 100644 (file)
@@ -1,6 +1,7 @@
 import { inject, Injectable } from '@angular/core';
 import { Router } from "@angular/router";
 import { Observable, of, throwError } from 'rxjs';
+import { delay } from 'rxjs/operators';
 
 @Injectable({
   providedIn: 'root'
@@ -16,7 +17,7 @@ export class AuthService {
       return throwError(() => new Error('Simulierter Fehler im Service'));
     }
     this.username = username;
-    return of(username);
+    return of(username).pipe(delay(1000));
   }
 
   assertUserIsKnown(): void {
index 5d495e72710806ce4f4fdde663ad72faa3431a85..951624abeb4e173811cb340bd782dbadda3a30cf 100644 (file)
@@ -15,6 +15,6 @@ const initialState: State = {
 
 export const loginReducers = createReducer(initialState,
   on(login, state => ({ ...state, isLoading: true })),
-  on(loginSuccess, (state, { token }) => ({ ...state, token, isLoading: false })),
-  on(loginFailure, (state, { error }) => ({ ...state, error, isLoading: false }))
+  on(loginSuccess, (state, { token }) => ({ ...state, token, error: null, isLoading: false })),
+  on(loginFailure, (state, { error }) => ({ ...state, token: null, error, isLoading: false }))
 );