Compare commits
No commits in common. "5a4df2572dfae456ca6552edb94d419a4d931b0f" and "3da46c203bd5dd7af3423ae4c052a8f6b5dd6d79" have entirely different histories.
5a4df2572d
...
3da46c203b
|
|
@ -1,15 +1,20 @@
|
|||
import {Injectable, signal} from '@angular/core';
|
||||
import {inject, Injectable, signal} from '@angular/core';
|
||||
import {LoginService} from '@api';
|
||||
import {Observable, throwError} from 'rxjs';
|
||||
import {catchError, tap} from 'rxjs/operators';
|
||||
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||
import {JwtHelperService} from '@auth0/angular-jwt';
|
||||
import {JwtClaims} from '@custom-types/jwt_interface'
|
||||
import {LoginDialogComponent} from '@shared-components/login/login.component';
|
||||
import {MatDialog} from '@angular/material/dialog';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthService {
|
||||
private dialog: MatDialog = inject(MatDialog)
|
||||
|
||||
private isAuthenticatedSubject = signal<boolean>(false);
|
||||
public readonly isAuthenticated$ = this.isAuthenticatedSubject.asReadonly();
|
||||
|
||||
|
|
@ -20,7 +25,8 @@ export class AuthService {
|
|||
|
||||
constructor(
|
||||
private loginService: LoginService,
|
||||
private snackBar: MatSnackBar
|
||||
private snackBar: MatSnackBar,
|
||||
private router: Router
|
||||
) {
|
||||
// Check if user is already logged in on service initialization
|
||||
this.checkAuthStatus();
|
||||
|
|
@ -72,6 +78,15 @@ export class AuthService {
|
|||
const jwt = this.getJwt();
|
||||
if (!jwt) {
|
||||
console.log("No JWT found");
|
||||
const currentUrl = this.router.url;
|
||||
const dialogRef = this.dialog.open(LoginDialogComponent, {
|
||||
width: '400px',
|
||||
})
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
if (result) {
|
||||
this.router.navigateByUrl(currentUrl).then();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user