-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathapp.component.ts
More file actions
49 lines (45 loc) · 1.85 KB
/
app.component.ts
File metadata and controls
49 lines (45 loc) · 1.85 KB
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
44
45
46
47
48
49
import { Component, OnInit } from '@angular/core'
import { Router } from '@angular/router'
import { OidcSecurityService } from 'angular-auth-oidc-client'
import { AccountService, StateStorageService } from './account'
import { EventService } from './shared/service/event.service'
import { EventType } from './app.constants'
import { Event } from './shared/model/event.model'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
constructor(
private oidcSecurityService: OidcSecurityService,
private accountService: AccountService,
private eventService: EventService,
private stateStorageService: StateStorageService,
private router: Router
) {}
ngOnInit() {
this.oidcSecurityService.checkAuth().subscribe(({ isAuthenticated, accessToken, errorMessage }) => {
console.log('App component - checkAuth result:', isAuthenticated)
if (isAuthenticated) {
console.log('app component fetching account data...')
this.accountService.getAccountData(true).subscribe(() => {
this.eventService.broadcast(new Event(EventType.LOG_IN_SUCCESS))
const redirect = this.stateStorageService.getUrl()
if (redirect) {
this.stateStorageService.storeUrl(null)
console.log('Redirecting to stored url after login:', redirect)
this.router.navigateByUrl(redirect)
} else if (this.router.url.includes('auth/callback')) {
console.log('Oauth callback, navigating to home page after login')
this.router.navigate(['/'])
}
})
} else {
console.error('OIDC Authentication FAILED or NOT LOGGED IN')
console.error('Error Message:', errorMessage)
console.log('Current Token:', accessToken)
}
})
}
}