-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathapp.component.ts
43 lines (38 loc) · 1.24 KB
/
app.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Component, OnInit } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { CommonModule } from '@angular/common';
import { OidcSecurityService } from 'angular-auth-oidc-client';
import type { UserInfoResponse } from '@logto/js';
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, CommonModule],
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
})
export class AppComponent implements OnInit {
title = '@logto/angular-sample';
isAuthenticated = false;
userData?: UserInfoResponse;
idToken?: string;
accessToken?: string;
constructor(public oidcSecurityService: OidcSecurityService) { }
ngOnInit() {
this.oidcSecurityService.checkAuth().subscribe(({ isAuthenticated, userData, idToken, accessToken }) => {
console.log('app authenticated', isAuthenticated, userData);
this.isAuthenticated = isAuthenticated;
this.userData = userData;
this.idToken = idToken;
this.accessToken = accessToken;
});
}
signIn() {
this.oidcSecurityService.authorize();
}
signOut() {
this.oidcSecurityService.logoff().subscribe((result) => {
console.log('app sign-out', result);
this.isAuthenticated = false;
});
}
}