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