From 08131705cc280e20d4b882e447309e3a7027a684 Mon Sep 17 00:00:00 2001 From: Art Date: Sun, 12 Sep 2021 12:15:13 +0300 Subject: [PATCH] 102. Save token to local storage (#12) --- .../src/app/service/authentication.service.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/support-portal-frontend/src/app/service/authentication.service.ts b/support-portal-frontend/src/app/service/authentication.service.ts index 789b9ac..4df7ab2 100644 --- a/support-portal-frontend/src/app/service/authentication.service.ts +++ b/support-portal-frontend/src/app/service/authentication.service.ts @@ -10,6 +10,8 @@ import {User} from "../model/user"; }) export class AuthenticationService { + private readonly JWT_TOKEN_STORAGE_KEY = "jwt-token"; + private host: string = environment.apiUrl; private token: string | null; private loggedInUser: string | null; @@ -31,8 +33,14 @@ export class AuthenticationService { public logout(): void { this.token = null; this.loggedInUser = null; - this.storage.removeItem("jwt-token"); + this.storage.removeItem(this.JWT_TOKEN_STORAGE_KEY); this.storage.removeItem("user"); this.storage.removeItem("users"); } + + public saveToken(token: string): void { + this.token = token; + this.storage.setItem(this.JWT_TOKEN_STORAGE_KEY, token); + } + }