frontend: Refactor authentication handling in components to use updated AuthService methods
This commit is contained in:
parent
411388ba53
commit
280dbea6dc
@ -24,6 +24,6 @@ export class ConsoleComponent {
|
||||
constructor(private authService: AuthService) {}
|
||||
|
||||
async logout() {
|
||||
await this.authService.adminLogout();
|
||||
await this.authService.logout('console/login');
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,15 @@ export class ConsoleLoginComponent {
|
||||
const { username, password } = this.loginForm.value;
|
||||
|
||||
try {
|
||||
await this.authService.adminLogin(username!, password!);
|
||||
await this.authService.login(username!, password!);
|
||||
|
||||
// Check if the user has the expected role
|
||||
if (!this.authService.isAdmin()) {
|
||||
this.authService.logout();
|
||||
this.loginErrorMessage = 'Invalid username or password';
|
||||
return;
|
||||
}
|
||||
|
||||
this.router.navigate(['console']);
|
||||
} catch (error) {
|
||||
if ((error as HttpErrorResponse).status === 429) {
|
||||
|
||||
@ -44,8 +44,15 @@ export class LoginComponent {
|
||||
const { username, password } = this.loginForm.value;
|
||||
|
||||
try {
|
||||
// TODO: Replace with user login
|
||||
await this.authService.adminLogin(username!, password!);
|
||||
await this.authService.login(username!, password!);
|
||||
|
||||
// Check if the user has the expected role
|
||||
if (this.authService.isAdmin()) {
|
||||
this.authService.logout();
|
||||
this.loginErrorMessage = 'Invalid username or password';
|
||||
return;
|
||||
}
|
||||
|
||||
this.router.navigate(['']);
|
||||
} catch (error) {
|
||||
if ((error as HttpErrorResponse).status === 429) {
|
||||
|
||||
@ -6,7 +6,7 @@ import { MatIconButton, MatButton } from '@angular/material/button';
|
||||
import { NgClass } from '@angular/common';
|
||||
import { MatToolbar } from '@angular/material/toolbar';
|
||||
import { Router } from '@angular/router';
|
||||
import { ContextService, HttpService } from '../../services/index';
|
||||
import { AuthService, ContextService, HttpService } from '../../services/index';
|
||||
import { OpenViduMeetRoom, OpenViduMeetRoomOptions } from '../../typings/ce/room';
|
||||
import { animals, colors, Config, uniqueNamesGenerator } from 'unique-names-generator';
|
||||
|
||||
@ -30,6 +30,7 @@ export class RoomCreatorComponent implements OnInit {
|
||||
constructor(
|
||||
private router: Router,
|
||||
private httpService: HttpService,
|
||||
private authService: AuthService,
|
||||
private contextService: ContextService
|
||||
) {}
|
||||
|
||||
@ -38,8 +39,7 @@ export class RoomCreatorComponent implements OnInit {
|
||||
this.openviduLogoUrl = this.contextService.getOpenViduLogoUrl();
|
||||
this.backgroundImageUrl = this.contextService.getBackgroundImageUrl();
|
||||
|
||||
// TODO: Retrieve actual username
|
||||
this.username = 'user';
|
||||
this.username = this.authService.getUsername();
|
||||
}
|
||||
|
||||
generateRoomName(event: any) {
|
||||
@ -53,7 +53,7 @@ export class RoomCreatorComponent implements OnInit {
|
||||
|
||||
async logout() {
|
||||
try {
|
||||
await this.httpService.userLogout();
|
||||
await this.authService.logout('login');
|
||||
} catch (error) {
|
||||
console.error('Error doing logout ', error);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user