feat: new token saving
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { HttpClient } from "@angular/common/http";
|
import { HttpClient } from "@angular/common/http";
|
||||||
import { Injectable, OnDestroy } from "@angular/core";
|
import { Injectable, OnDestroy } from "@angular/core";
|
||||||
import { Observable, Subject, catchError, map, of, takeUntil } from "rxjs";
|
import { Observable, Subject, catchError, map, of, takeUntil } from "rxjs";
|
||||||
|
import { IToken } from "../token.dto";
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: "root",
|
providedIn: "root",
|
||||||
})
|
})
|
||||||
@@ -10,19 +11,21 @@ export class RulibAuthService implements OnDestroy {
|
|||||||
constructor(private http: HttpClient) {}
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
setToken(token: string): Observable<boolean> {
|
setToken(token: string): Observable<boolean> {
|
||||||
return this.checkToken(token)
|
return this.checkToken(token).pipe(
|
||||||
.pipe(takeUntil(this.destroy$))
|
takeUntil(this.destroy$),
|
||||||
.pipe(
|
map((data) => {
|
||||||
map((data) => {
|
if (!data) return false;
|
||||||
if (!data) return false;
|
const token_data: IToken = JSON.parse(localStorage.getItem("token") ?? "{}");
|
||||||
localStorage.setItem("token", token);
|
token_data.rulib_token = token;
|
||||||
return true;
|
localStorage.setItem("token", JSON.stringify(token_data));
|
||||||
}),
|
return true;
|
||||||
);
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getToken(): string {
|
getToken(): string {
|
||||||
return localStorage.getItem("token") ?? "";
|
const token_data: IToken = JSON.parse(localStorage.getItem("token") ?? "{}");
|
||||||
|
return token_data.rulib_token ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
checkToken(token: string): Observable<boolean> {
|
checkToken(token: string): Observable<boolean> {
|
||||||
|
|||||||
3
apps/NwaifuAnime/src/app/services/parsers/token.dto.ts
Normal file
3
apps/NwaifuAnime/src/app/services/parsers/token.dto.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export interface IToken {
|
||||||
|
rulib_token?: string;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user