diff --git a/Weifer.ShoppingApp.Frontend_/src/app/shared/components/login-form/login-form.component.ts b/Weifer.ShoppingApp.Frontend_/src/app/shared/components/login-form/login-form.component.ts index 3b811c4..f72fa7e 100644 --- a/Weifer.ShoppingApp.Frontend_/src/app/shared/components/login-form/login-form.component.ts +++ b/Weifer.ShoppingApp.Frontend_/src/app/shared/components/login-form/login-form.component.ts @@ -51,9 +51,7 @@ export class LoginFormComponent { } rememberMeChanged = (e: any) => { - this.remember_me = e.value; - console.log(this.remember_me) } onCreateAccountClick = () => { this.router.navigate(['/create-account']); diff --git a/Weifer.ShoppingApp.Frontend_/src/app/shared/services/auth.service.ts b/Weifer.ShoppingApp.Frontend_/src/app/shared/services/auth.service.ts index 25bfc9a..b8bc592 100644 --- a/Weifer.ShoppingApp.Frontend_/src/app/shared/services/auth.service.ts +++ b/Weifer.ShoppingApp.Frontend_/src/app/shared/services/auth.service.ts @@ -43,7 +43,7 @@ export class AuthService { avatarUrl: "https://js.devexpress.com/Demos/WidgetsGallery/JSDemos/images/employees/07.png" }; localStorage.setItem('access_token', result.token); - // localStorage.setItem('user_data', JSON.stringify(this.user)); + localStorage.setItem('user_data', JSON.stringify(this.user)); } if (rememberMe) { localStorage.setItem('remember_me', 'true'); @@ -54,12 +54,11 @@ export class AuthService { checkAuthenticationStatus(): void { const token = localStorage.getItem('access_token'); const rememberMe = localStorage.getItem('remember_me') === 'true'; - //const userData = localStorage.getItem('user_data'); - //if (userData) { - // this.user = JSON.parse(userData); - //} + const userData = localStorage.getItem('user_data'); + if (userData) { + this.user = JSON.parse(userData); + } if (token && rememberMe) { - // Erstellen des Headers mit dem Token const headers = new HttpHeaders({ 'Authorization': token, }); @@ -70,18 +69,16 @@ export class AuthService { }, error: (err) => { console.error(err); - this.logOut(); // Bereinigung im Fehlerfall + this.logOut(); } }); } else { - this.logOut(); // Bereinigung, falls Remember Me nicht gesetzt ist + this.logOut(); } } async getUser() { try { - // Send request - return { isOk: true, data: this.user @@ -102,7 +99,6 @@ export class AuthService { async createAccount(newUser: CustomerDto) { try { const result = await firstValueFrom(this.http.post(`${API_URL}/customerapi/add`, newUser )); - //this.router.navigate(['/create-account']); return { isOk: true }; @@ -149,9 +145,9 @@ export class AuthService { async logOut() { this.user = null; - // Bereinigen des lokalen Speichers localStorage.removeItem('access_token'); localStorage.removeItem('remember_me'); + localStorage.removeItem('user_data'); this.router.navigate(['/login-form']); } }