feat(login): log user info on successful login success page
Some checks failed
Some checks failed
This commit is contained in:
parent
3da534f3ae
commit
7eebd12699
2 changed files with 6 additions and 18 deletions
|
@ -12,8 +12,8 @@ import { User } from '../../model/User';
|
|||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export default class LoginSuccessComponent implements OnInit {
|
||||
private router: Router = inject(Router);
|
||||
private authService: AuthService = inject(AuthService);
|
||||
async ngOnInit() {
|
||||
console.log(this.authService.getUser())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { inject, Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { AuthConfig, OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
|
||||
import { AuthConfig, OAuthService } from 'angular-oauth2-oidc';
|
||||
import { UserService } from './user.service';
|
||||
import { User } from '../model/User';
|
||||
import { Router } from '@angular/router';
|
||||
|
@ -23,41 +22,28 @@ export class AuthService {
|
|||
strictDiscoveryDocumentValidation: false,
|
||||
skipIssuerCheck: true,
|
||||
disableAtHashCheck: true,
|
||||
jwks: {
|
||||
skipJwksValidation: true,
|
||||
}
|
||||
};
|
||||
|
||||
private userService: UserService = inject(UserService);
|
||||
private oauthService: OAuthService = inject(OAuthService);
|
||||
private oauthStorage: OAuthStorage = inject(OAuthStorage);
|
||||
private router: Router = inject(Router);
|
||||
|
||||
private isAuthenticated = new Subject<boolean>();
|
||||
private user: User | null = null;
|
||||
|
||||
constructor() {
|
||||
console.log(1);
|
||||
this.oauthService.setStorage(localStorage);
|
||||
this.oauthService.configure(this.authConfig);
|
||||
this.oauthService.events.subscribe((event) => {
|
||||
console.log(2, event.type);
|
||||
if (event.type === 'token_received') {
|
||||
console.log(3);
|
||||
this.oauthStorage.setItem('jwt', this.getAccessToken());
|
||||
this.oauthService.loadUserProfile().then((profile) => {
|
||||
console.log(4);
|
||||
console.log(profile);
|
||||
this.fromUserProfile(profile).subscribe((user) => {
|
||||
console.log(5);
|
||||
this.user = user;
|
||||
console.log(user);
|
||||
this.router.navigate(['home']);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
this.oauthService.loadDiscoveryDocumentAndTryLogin().then(() => {
|
||||
this.isAuthenticated.next(this.oauthService.hasValidAccessToken());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -67,7 +53,6 @@ export class AuthService {
|
|||
|
||||
logout() {
|
||||
this.oauthService.logOut();
|
||||
this.isAuthenticated.next(false);
|
||||
}
|
||||
|
||||
isLoggedIn() {
|
||||
|
@ -81,4 +66,7 @@ export class AuthService {
|
|||
getAccessToken() {
|
||||
return this.oauthService.getAccessToken();
|
||||
}
|
||||
getUser() {
|
||||
return this.user;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue