mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Merged PR 2001: fix(auth): handle empty user state on login
fix(auth): handle empty user state on login Resolves error when user state is empty during login process. Refs #5431 Related work items: #5431
This commit is contained in:
committed by
Nino Righi
parent
ce86014300
commit
e1681d8867
@@ -1,15 +1,34 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { toObservable } from '@angular/core/rxjs-interop';
|
||||
import { StorageProvider } from './storage-provider';
|
||||
import { UserStateService } from '@generated/swagger/isa-api';
|
||||
import { filter, firstValueFrom, retry, switchMap, tap, timer } from 'rxjs';
|
||||
import {
|
||||
ResponseArgsOfUserState,
|
||||
UserStateService,
|
||||
} from '@generated/swagger/isa-api';
|
||||
import {
|
||||
catchError,
|
||||
filter,
|
||||
firstValueFrom,
|
||||
retry,
|
||||
switchMap,
|
||||
tap,
|
||||
throwError,
|
||||
timer,
|
||||
} from 'rxjs';
|
||||
import { USER_SUB } from '../tokens';
|
||||
import { Debounce, ValidateParam } from '@isa/common/decorators';
|
||||
import z from 'zod';
|
||||
import { logger } from '@isa/core/logging';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
type UserState = Record<string, unknown>;
|
||||
|
||||
const DEFAULT_USER_STATE_RESPONSE: ResponseArgsOfUserState = {
|
||||
result: { content: '{}' },
|
||||
error: false,
|
||||
message: 'User state not found',
|
||||
};
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class UserStorageProvider implements StorageProvider {
|
||||
#logger = logger(() => ({
|
||||
@@ -22,6 +41,12 @@ export class UserStorageProvider implements StorageProvider {
|
||||
filter((sub) => sub !== 'anonymous'),
|
||||
switchMap(() =>
|
||||
this.#userStateService.UserStateGetUserState().pipe(
|
||||
catchError((error) => {
|
||||
if (error instanceof HttpErrorResponse && error.status === 404) {
|
||||
return [DEFAULT_USER_STATE_RESPONSE];
|
||||
}
|
||||
return throwError(() => error);
|
||||
}),
|
||||
retry({
|
||||
count: 3,
|
||||
delay: (error, retryCount) => {
|
||||
|
||||
Reference in New Issue
Block a user