-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,50 @@ | ||
import {Injectable} from "@angular/core"; | ||
import {ExtendedUser} from "./types/extended-user"; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
providedIn: 'root' | ||
}) | ||
export class TokenStorageService { | ||
private readonly GameTokenKey: string = "game_token"; | ||
private readonly RefreshTokenKey: string = "refresh_token"; | ||
private readonly GameTokenKey: string = "game_token"; | ||
private readonly RefreshTokenKey: string = "refresh_token"; | ||
private readonly UserKey: string = "cached_user_data"; | ||
|
||
public GetStoredGameToken(): string | null { | ||
return localStorage.getItem(this.GameTokenKey); | ||
} | ||
public GetStoredGameToken(): string | null { | ||
return localStorage.getItem(this.GameTokenKey); | ||
} | ||
|
||
public SetStoredGameToken(token: string): void { | ||
localStorage.setItem(this.GameTokenKey, token); | ||
} | ||
public SetStoredGameToken(token: string): void { | ||
localStorage.setItem(this.GameTokenKey, token); | ||
} | ||
|
||
public ClearStoredGameToken(): void { | ||
localStorage.removeItem(this.GameTokenKey); | ||
} | ||
public ClearStoredGameToken(): void { | ||
localStorage.removeItem(this.GameTokenKey); | ||
} | ||
|
||
public GetStoredRefreshToken(): string | null { | ||
return localStorage.getItem(this.RefreshTokenKey); | ||
} | ||
public GetStoredRefreshToken(): string | null { | ||
return localStorage.getItem(this.RefreshTokenKey); | ||
} | ||
|
||
public SetStoredRefreshToken(refreshToken: string): void { | ||
localStorage.setItem(this.RefreshTokenKey, refreshToken); | ||
} | ||
public SetStoredRefreshToken(refreshToken: string): void { | ||
localStorage.setItem(this.RefreshTokenKey, refreshToken); | ||
} | ||
|
||
public ClearStoredRefreshToken(): void { | ||
localStorage.removeItem(this.RefreshTokenKey); | ||
} | ||
public ClearStoredRefreshToken(): void { | ||
localStorage.removeItem(this.RefreshTokenKey); | ||
} | ||
|
||
public GetStoredUser(): ExtendedUser | null { | ||
const str = localStorage.getItem(this.UserKey); | ||
if(!str) return null; | ||
|
||
return JSON.parse(str); | ||
} | ||
|
||
public SetStoredUser(user: ExtendedUser): void { | ||
localStorage.setItem(this.UserKey, JSON.stringify(user)); | ||
} | ||
|
||
public ClearStoredUser(): void { | ||
localStorage.removeItem(this.UserKey); | ||
} | ||
} |