Minor changes for updating JWT token.
This commit is contained in:
parent
b8a92534d9
commit
0a511f1424
@ -87,7 +87,7 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
if (!isPlatformBrowser(this.platformId))
|
||||
return;
|
||||
|
||||
this.auth.update();
|
||||
this.auth.update(localStorage.getItem('jwt'));
|
||||
|
||||
this.subscriptions.push(this.events.listen('login', async () => await this.router.navigate(['tts-login'])));
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import EventService from '../EventService';
|
||||
import { environment } from '../../../../environments/environment';
|
||||
|
||||
@ -7,16 +7,17 @@ import { environment } from '../../../../environments/environment';
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ApiAuthenticationService {
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly events = inject(EventService);
|
||||
|
||||
private authenticated: boolean;
|
||||
private user: any;
|
||||
private lastCheck: Date;
|
||||
|
||||
constructor(private http: HttpClient, private events: EventService) {
|
||||
constructor() {
|
||||
this.authenticated = false;
|
||||
this.user = null;
|
||||
this.lastCheck = new Date();
|
||||
|
||||
this.events.listen('impersonation', _ => this.update());
|
||||
}
|
||||
|
||||
isAuthenticated() {
|
||||
@ -44,8 +45,7 @@ export class ApiAuthenticationService {
|
||||
this.updateAuthenticated(false, null);
|
||||
}
|
||||
|
||||
update() {
|
||||
const jwt = localStorage.getItem('jwt');
|
||||
update(jwt: string | null) {
|
||||
if (!jwt) {
|
||||
this.updateAuthenticated(false, null);
|
||||
return;
|
||||
@ -72,7 +72,6 @@ export class ApiAuthenticationService {
|
||||
if (authenticated) {
|
||||
this.events.emit('login', null);
|
||||
} else {
|
||||
localStorage.removeItem('jwt');
|
||||
this.events.emit('logoff', null);
|
||||
}
|
||||
}
|
||||
|
@ -52,9 +52,7 @@ export class TwitchAuthCallbackComponent implements OnInit, OnDestroy {
|
||||
this.http.post(environment.API_HOST + '/auth/twitch/callback', { code, scope, state })
|
||||
.subscribe({
|
||||
next: async (response: any) => {
|
||||
console.log('twitch api callback response:', response);
|
||||
localStorage.setItem('jwt', response.token);
|
||||
this.auth.update();
|
||||
this.auth.update(response.token);
|
||||
},
|
||||
error: async () => await this.router.navigate(['login'], {
|
||||
queryParams: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user