ajout logout
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build is passing Details

pull/14/head
Hugo PRADIER 10 months ago
parent 2d5c4f126e
commit 2aafd3e320

@ -106,6 +106,10 @@
[routerLinkActiveOptions]="{ exact: true }">
<span>Register Now</span>
</button>
<!-- Logout -->
<button class="right_part__connexion--logout" (click)="logout()">
<span>Logout</span>
</button>
</div>
</div>
</div>
@ -187,6 +191,10 @@
[routerLinkActiveOptions]="{ exact: true }">
<span>Register Now</span>
</button>
<!-- Logout -->
<button class="right_part__connexion--logout" (click)="logout()">
<span>Logout</span>
</button>
</div>
</div>
</div>

@ -11,6 +11,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { ReactiveFormsModule } from '@angular/forms';
import { RouterLink, RouterLinkActive } from '@angular/router';
import { NgClass, NgOptimizedImage } from '@angular/common';
import { UserService } from 'src/app/services/user.service';
@Component({
selector: 'app-header',
@ -36,7 +37,10 @@ export class HeaderComponent {
@Input() themeService!: ThemeService;
// Instanciation du service pour les actions de traduction
constructor(private translationService: TranslationService) {}
constructor(
private translationService: TranslationService,
private userService: UserService
) {}
// Méthode pour changer la langue
onLanguageChange(event: Event) {
@ -63,4 +67,15 @@ export class HeaderComponent {
document.body.classList.remove('no-scroll');
}
}
// Logout
logout() {
this.userService.logoutUser().subscribe((response) => {
if (response.success) {
console.log('Logout success');
} else {
console.log('Logout error');
}
});
}
}

@ -33,7 +33,15 @@ export class UserService {
password: password,
};
return this.http.post<Response>(`${this.API_URL}/users/login`, body);
return this.http.post<Response>(`${this.API_URL}/users/login`, body, {
withCredentials: true,
});
}
logoutUser(): Observable<Response> {
return this.http.post<Response>(`${this.API_URL}/users/logout`, {
withCredentials: true,
});
}
}

Loading…
Cancel
Save