cookie init

This commit is contained in:
2023-05-03 11:55:26 +02:00
parent 3768f8ef0e
commit cd751b529b
6 changed files with 56 additions and 9 deletions

View File

@@ -0,0 +1,34 @@
import {Injectable} from '@angular/core';
import {CookieService} from 'ngx-cookie-service';
import {Router} from "@angular/router";
@Injectable({
providedIn: 'root'
})
export class cookieService {
constructor(
private coockieService: CookieService,
private router: Router,
) {
}
setUsername(username: string): void {
this.coockieService.set('username', username);
}
getUsername(): string {
let username = this.coockieService.get('username');
if (username == null) {
this.router.navigate(['/login']);
return '';
} else {
return username;
}
}
deleteUsername(): void {
this.coockieService.delete('username');
}
}