From c427c6d0b4f9e99fb256f5dec4c1903012d524b8 Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Thu, 18 Jul 2024 15:41:09 +0300 Subject: [PATCH] feat: new token saving --- .../parsers/rulib/rulib.auth.service.ts | 23 +++++++++++-------- .../src/app/services/parsers/token.dto.ts | 3 +++ 2 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 apps/NwaifuAnime/src/app/services/parsers/token.dto.ts diff --git a/apps/NwaifuAnime/src/app/services/parsers/rulib/rulib.auth.service.ts b/apps/NwaifuAnime/src/app/services/parsers/rulib/rulib.auth.service.ts index 47e0f4d..e23bd4d 100644 --- a/apps/NwaifuAnime/src/app/services/parsers/rulib/rulib.auth.service.ts +++ b/apps/NwaifuAnime/src/app/services/parsers/rulib/rulib.auth.service.ts @@ -1,6 +1,7 @@ import { HttpClient } from "@angular/common/http"; import { Injectable, OnDestroy } from "@angular/core"; import { Observable, Subject, catchError, map, of, takeUntil } from "rxjs"; +import { IToken } from "../token.dto"; @Injectable({ providedIn: "root", }) @@ -10,19 +11,21 @@ export class RulibAuthService implements OnDestroy { constructor(private http: HttpClient) {} setToken(token: string): Observable { - return this.checkToken(token) - .pipe(takeUntil(this.destroy$)) - .pipe( - map((data) => { - if (!data) return false; - localStorage.setItem("token", token); - return true; - }), - ); + return this.checkToken(token).pipe( + takeUntil(this.destroy$), + map((data) => { + if (!data) return false; + const token_data: IToken = JSON.parse(localStorage.getItem("token") ?? "{}"); + token_data.rulib_token = token; + localStorage.setItem("token", JSON.stringify(token_data)); + return true; + }), + ); } getToken(): string { - return localStorage.getItem("token") ?? ""; + const token_data: IToken = JSON.parse(localStorage.getItem("token") ?? "{}"); + return token_data.rulib_token ?? ""; } checkToken(token: string): Observable { diff --git a/apps/NwaifuAnime/src/app/services/parsers/token.dto.ts b/apps/NwaifuAnime/src/app/services/parsers/token.dto.ts new file mode 100644 index 0000000..7f64c09 --- /dev/null +++ b/apps/NwaifuAnime/src/app/services/parsers/token.dto.ts @@ -0,0 +1,3 @@ +export interface IToken { + rulib_token?: string; +}