Allow frontend auth token bootstrap from URL
This commit is contained in:
@@ -30,9 +30,23 @@ export class AppComponent {
|
|||||||
private readonly playlistService: PlaylistService,
|
private readonly playlistService: PlaylistService,
|
||||||
private readonly versionService: VersionService,
|
private readonly versionService: VersionService,
|
||||||
) {
|
) {
|
||||||
|
this.bootstrapAuthTokenFromUrl();
|
||||||
this.fetchPlaylists();
|
this.fetchPlaylists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bootstrapAuthTokenFromUrl(): void {
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
const token = url.searchParams.get('token');
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.setItem('spooty_auth_token', token);
|
||||||
|
url.searchParams.delete('token');
|
||||||
|
window.history.replaceState({}, document.title, url.toString());
|
||||||
|
}
|
||||||
|
|
||||||
fetchPlaylists(): void {
|
fetchPlaylists(): void {
|
||||||
this.playlistService.fetch();
|
this.playlistService.fetch();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user