satisfy quality tools
This commit is contained in:
parent
df9fa9f275
commit
2326d41a96
@ -1,11 +1,8 @@
|
|||||||
import { ActivatedRouteSnapshot, CanActivateFn, Router, RouterStateSnapshot } from '@angular/router';
|
import { CanActivateFn, Router } from '@angular/router';
|
||||||
import { inject } from '@angular/core';
|
import { inject } from '@angular/core';
|
||||||
import { KeycloakService } from 'keycloak-angular';
|
import { KeycloakService } from 'keycloak-angular';
|
||||||
|
|
||||||
export const authGuard: CanActivateFn = async (
|
export const authGuard: CanActivateFn = async () => {
|
||||||
route: ActivatedRouteSnapshot,
|
|
||||||
state: RouterStateSnapshot
|
|
||||||
) => {
|
|
||||||
const keycloakService = inject(KeycloakService);
|
const keycloakService = inject(KeycloakService);
|
||||||
const router = inject(Router);
|
const router = inject(Router);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import { Router } from '@angular/router';
|
|||||||
styleUrl: './login-success.component.css',
|
styleUrl: './login-success.component.css',
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class LoginSuccessComponent implements OnInit{
|
export class LoginSuccessComponent implements OnInit {
|
||||||
private userService: UserService = inject(UserService);
|
private userService: UserService = inject(UserService);
|
||||||
private keycloakService: KeycloakService = inject(KeycloakService);
|
private keycloakService: KeycloakService = inject(KeycloakService);
|
||||||
private router: Router = inject(Router);
|
private router: Router = inject(Router);
|
||||||
@ -21,6 +21,6 @@ export class LoginSuccessComponent implements OnInit{
|
|||||||
const user = await this.userService.getOrCreateUser(userProfile);
|
const user = await this.userService.getOrCreateUser(userProfile);
|
||||||
sessionStorage.setItem('user', JSON.stringify(user));
|
sessionStorage.setItem('user', JSON.stringify(user));
|
||||||
|
|
||||||
// this.router.navigate(['']);
|
this.router.navigate(['']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { inject, Injectable } from '@angular/core';
|
import { inject, Injectable } from '@angular/core';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { KeycloakProfile } from 'keycloak-js';
|
import { KeycloakProfile } from 'keycloak-js';
|
||||||
import { async, Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { User } from '../model/User';
|
import { User } from '../model/User';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
@ -10,8 +10,8 @@ import { User } from '../model/User';
|
|||||||
export class UserService {
|
export class UserService {
|
||||||
private http: HttpClient = inject(HttpClient);
|
private http: HttpClient = inject(HttpClient);
|
||||||
|
|
||||||
public getUser(id: string): Observable<User|null> {
|
public getUser(id: string): Observable<User | null> {
|
||||||
return this.http.get<User|null>(`/backend/user/${id}`);
|
return this.http.get<User | null>(`/backend/user/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public createUser(id: string, username: string): Observable<User> {
|
public createUser(id: string, username: string): Observable<User> {
|
||||||
@ -25,11 +25,13 @@ export class UserService {
|
|||||||
if (userProfile.id == null) {
|
if (userProfile.id == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return await this.getUser(userProfile.id).toPromise().then(async user => {
|
return await this.getUser(userProfile.id)
|
||||||
if (user) {
|
.toPromise()
|
||||||
return user;
|
.then(async (user) => {
|
||||||
}
|
if (user) {
|
||||||
return await this.createUser(userProfile.id ?? '', userProfile.username ?? '').toPromise();
|
return user;
|
||||||
});
|
}
|
||||||
|
return await this.createUser(userProfile.id ?? '', userProfile.username ?? '').toPromise();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user