You need to sign in or sign up before continuing.
Commit b85aa0f9 by zadi francice

authenfication

parent 8c50e5d3
...@@ -76,7 +76,6 @@ export class LoginStandardUserComponent implements OnInit { ...@@ -76,7 +76,6 @@ export class LoginStandardUserComponent implements OnInit {
isActive = false; isActive = false;
msgAuth = ''; msgAuth = '';
// eslint-disable-next-line @angular-eslint/no-empty-lifecycle-method // eslint-disable-next-line @angular-eslint/no-empty-lifecycle-method
ngOnInit() { ngOnInit() {
this.user = { this.user = {
...@@ -91,14 +90,24 @@ export class LoginStandardUserComponent implements OnInit { ...@@ -91,14 +90,24 @@ export class LoginStandardUserComponent implements OnInit {
password: this.user.password, password: this.user.password,
}); });
let token: string;
console.log('Token ==> ', this.authService.token);
if (this.authService.token) { if (this.authService.token) {
this.authService.verifyToken(this.authService.token).subscribe(result => { token = this.authService.token;
} else {
const localStorageToken = localStorage.getItem('token');
token = localStorageToken ? String(localStorageToken) : '';
}
console.log('Token ==> ', token);
if (token) {
this.authService.verifyToken(token).subscribe(result => {
if (result.status) { if (result.status) {
console.log('Token vérifié avec succès'); console.log('Token vérifié avec succès');
console.log('accessToken', this.authService.token); console.log('accessToken', token);
localStorage.setItem('isLoggedIn', 'true'); localStorage.setItem('isLoggedIn', 'true');
localStorage.setItem('token', this.user.username); localStorage.setItem('token', token);
// Remplacez 'page-accueil' par l'URL de la page à laquelle vous souhaitez rediriger localStorage.setItem('username', this.user.username);
// Remplacez 'dash' par l'URL de la page à laquelle vous souhaitez rediriger
console.log("Redirection vers 'dash'"); console.log("Redirection vers 'dash'");
this.router.navigate(['/admin']); this.router.navigate(['/admin']);
} else { } else {
...@@ -106,7 +115,7 @@ export class LoginStandardUserComponent implements OnInit { ...@@ -106,7 +115,7 @@ export class LoginStandardUserComponent implements OnInit {
} }
}); });
} else { } else {
console.log('token non identifié'); console.log('Token non trouvé');
} }
} }
......
...@@ -13,16 +13,14 @@ import { Router } from '@angular/router'; ...@@ -13,16 +13,14 @@ import { Router } from '@angular/router';
export class NavbarComponent { export class NavbarComponent {
userEmail: string | null | undefined; userEmail: string | null | undefined;
ngOnInit() { ngOnInit() {
this.userEmail = localStorage.getItem('token'); this.userEmail = localStorage.getItem('username');
console.log(this.userEmail); console.log(this.userEmail);
} }
private router = inject(Router) private router = inject(Router);
deconnxionlogin() deconnxionlogin() {
{ localStorage.setItem('isLoggedIn', 'false');
localStorage.setItem('isLoggedIn', "false");
localStorage.removeItem('token'); localStorage.removeItem('token');
// // Remplacez 'page-accueil' par l'URL de la page à laquelle vous souhaitez rediriger // // Remplacez 'page-accueil' par l'URL de la page à laquelle vous souhaitez rediriger
// console.log("Redirection vers 'dash'"); // console.log("Redirection vers 'dash'");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment