mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-23 15:30:34 -04:00
Handling autologin and logout
This commit is contained in:
parent
d3a860fa8f
commit
a0f8fe4de4
@ -1,6 +1,7 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from "@angular/core";
|
||||||
import { OidcSecurityService } from "angular-auth-oidc-client";
|
import { OidcSecurityService } from "angular-auth-oidc-client";
|
||||||
import { Account } from "../models/account";
|
import { Account } from "../models/account";
|
||||||
|
import {HttpClient} from "@angular/common/http";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: "root"
|
providedIn: "root"
|
||||||
@ -10,15 +11,17 @@ export class AuthService
|
|||||||
isAuthenticated: boolean = false;
|
isAuthenticated: boolean = false;
|
||||||
account: Account = null;
|
account: Account = null;
|
||||||
|
|
||||||
constructor(private oidcSecurityService: OidcSecurityService)
|
constructor(private oidcSecurityService: OidcSecurityService, private http: HttpClient)
|
||||||
{
|
{
|
||||||
this.oidcSecurityService.checkAuth()
|
this.oidcSecurityService.checkAuth()
|
||||||
.subscribe((auth: boolean) => this.isAuthenticated = auth);
|
.subscribe((auth: boolean) => this.isAuthenticated = auth);
|
||||||
this.oidcSecurityService.userData$.subscribe(x =>
|
this.oidcSecurityService.userData$.subscribe(x =>
|
||||||
{
|
{
|
||||||
if (x == null)
|
if (x == null)
|
||||||
|
{
|
||||||
|
this.account = null;
|
||||||
return;
|
return;
|
||||||
console.log(x);
|
}
|
||||||
this.account = {
|
this.account = {
|
||||||
email: x.email,
|
email: x.email,
|
||||||
username: x.username,
|
username: x.username,
|
||||||
@ -35,10 +38,9 @@ export class AuthService
|
|||||||
|
|
||||||
logout(): void
|
logout(): void
|
||||||
{
|
{
|
||||||
// this.http.get("api/account/logout").subscribe(() =>
|
this.http.get("api/account/logout").subscribe(() =>
|
||||||
// {
|
{
|
||||||
this.oidcSecurityService.logoff();
|
this.oidcSecurityService.logoff();
|
||||||
// document.cookie = "Authenticated=false; expires=" + new Date(2147483647 * 1000).toUTCString();
|
});
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ export class AuthorizerInterceptor implements HttpInterceptor
|
|||||||
if (this.oidcSecurity === undefined)
|
if (this.oidcSecurity === undefined)
|
||||||
this.oidcSecurity = this.injector.get(OidcSecurityService);
|
this.oidcSecurity = this.injector.get(OidcSecurityService);
|
||||||
const token: string = this.oidcSecurity.getToken();
|
const token: string = this.oidcSecurity.getToken();
|
||||||
console.log(request.url, token);
|
|
||||||
if (token)
|
if (token)
|
||||||
request = request.clone({setHeaders: {Authorization: "Bearer " + token}});
|
request = request.clone({setHeaders: {Authorization: "Bearer " + token}});
|
||||||
return next.handle(request);
|
return next.handle(request);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user