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