mirror of
https://github.com/zitadel/zitadel.git
synced 2025-03-01 07:07:24 +00:00
fix: load using auth service
This commit is contained in:
parent
e79d7087a7
commit
af3c3d4c66
@ -5,19 +5,7 @@ import { MatDialog } from '@angular/material/dialog';
|
|||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
import {
|
import { defer, EMPTY, fromEvent, mergeWith, Observable, of, shareReplay, Subject, switchMap, take } from 'rxjs';
|
||||||
combineLatestWith,
|
|
||||||
defer,
|
|
||||||
EMPTY,
|
|
||||||
fromEvent,
|
|
||||||
mergeWith,
|
|
||||||
Observable,
|
|
||||||
of,
|
|
||||||
shareReplay,
|
|
||||||
Subject,
|
|
||||||
switchMap,
|
|
||||||
take,
|
|
||||||
} from 'rxjs';
|
|
||||||
import { ChangeType } from 'src/app/modules/changes/changes.component';
|
import { ChangeType } from 'src/app/modules/changes/changes.component';
|
||||||
import { phoneValidator, requiredValidator } from 'src/app/modules/form-field/validators/validators';
|
import { phoneValidator, requiredValidator } from 'src/app/modules/form-field/validators/validators';
|
||||||
import { InfoDialogComponent } from 'src/app/modules/info-dialog/info-dialog.component';
|
import { InfoDialogComponent } from 'src/app/modules/info-dialog/info-dialog.component';
|
||||||
@ -37,7 +25,7 @@ import { formatPhone } from 'src/app/utils/formatPhone';
|
|||||||
import { EditDialogComponent, EditDialogData, EditDialogResult, EditDialogType } from './edit-dialog/edit-dialog.component';
|
import { EditDialogComponent, EditDialogData, EditDialogResult, EditDialogType } from './edit-dialog/edit-dialog.component';
|
||||||
import { LanguagesService } from 'src/app/services/languages.service';
|
import { LanguagesService } from 'src/app/services/languages.service';
|
||||||
import { Gender, HumanProfile, HumanUser, User, UserState } from '@zitadel/proto/zitadel/user/v2/user_pb';
|
import { Gender, HumanProfile, HumanUser, User, UserState } from '@zitadel/proto/zitadel/user/v2/user_pb';
|
||||||
import { catchError, filter, map, startWith, tap, withLatestFrom } from 'rxjs/operators';
|
import { catchError, filter, map, startWith, withLatestFrom } from 'rxjs/operators';
|
||||||
import { pairwiseStartWith } from 'src/app/utils/pairwiseStartWith';
|
import { pairwiseStartWith } from 'src/app/utils/pairwiseStartWith';
|
||||||
import { NewAuthService } from 'src/app/services/new-auth.service';
|
import { NewAuthService } from 'src/app/services/new-auth.service';
|
||||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||||
@ -46,7 +34,6 @@ import { Metadata } from '@zitadel/proto/zitadel/metadata_pb';
|
|||||||
import { UserService } from 'src/app/services/user.service';
|
import { UserService } from 'src/app/services/user.service';
|
||||||
import { LoginPolicy } from '@zitadel/proto/zitadel/policy_pb';
|
import { LoginPolicy } from '@zitadel/proto/zitadel/policy_pb';
|
||||||
import { query } from '@angular/animations';
|
import { query } from '@angular/animations';
|
||||||
import { withLatestFromSynchronousFix } from '../../../../utils/withLatestFromSynchronousFix';
|
|
||||||
|
|
||||||
type UserQuery = { state: 'success'; value: User } | { state: 'error'; error: any } | { state: 'loading'; value?: User };
|
type UserQuery = { state: 'success'; value: User } | { state: 'error'; error: any } | { state: 'loading'; value?: User };
|
||||||
|
|
||||||
@ -112,7 +99,7 @@ export class AuthUserDetailComponent implements OnInit {
|
|||||||
this.user$ = this.getUser$().pipe(shareReplay({ refCount: true, bufferSize: 1 }));
|
this.user$ = this.getUser$().pipe(shareReplay({ refCount: true, bufferSize: 1 }));
|
||||||
this.userName$ = this.getUserName(this.user$);
|
this.userName$ = this.getUserName(this.user$);
|
||||||
this.savedLanguage$ = this.getSavedLanguage$(this.user$);
|
this.savedLanguage$ = this.getSavedLanguage$(this.user$);
|
||||||
this.metadata$ = this.getMetadata$(this.user$).pipe(shareReplay({ refCount: true, bufferSize: 1 }));
|
this.metadata$ = this.getMetadata$().pipe(shareReplay({ refCount: true, bufferSize: 1 }));
|
||||||
|
|
||||||
this.loginPolicy$ = defer(() => this.newMgmtService.getLoginPolicy()).pipe(
|
this.loginPolicy$ = defer(() => this.newMgmtService.getLoginPolicy()).pipe(
|
||||||
catchError(() => EMPTY),
|
catchError(() => EMPTY),
|
||||||
@ -212,25 +199,10 @@ export class AuthUserDetailComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMetadata$(user$: Observable<UserQuery>): Observable<MetadataQuery> {
|
getMetadata$(): Observable<MetadataQuery> {
|
||||||
const isAllowed$ = this.grpcAuthService.isAllowed(['user.read']);
|
|
||||||
|
|
||||||
return this.refreshMetadata$.pipe(
|
return this.refreshMetadata$.pipe(
|
||||||
startWith(true),
|
startWith(true),
|
||||||
combineLatestWith(user$),
|
switchMap(() => this.getMetadata()),
|
||||||
withLatestFromSynchronousFix(isAllowed$),
|
|
||||||
switchMap(([[_, user], isAllowed]): Observable<MetadataQuery> => {
|
|
||||||
if (!isAllowed) {
|
|
||||||
return of({ state: 'success', value: [] });
|
|
||||||
}
|
|
||||||
if (!(user.state === 'success' || user.state === 'loading')) {
|
|
||||||
return EMPTY;
|
|
||||||
}
|
|
||||||
if (!user.value) {
|
|
||||||
return EMPTY;
|
|
||||||
}
|
|
||||||
return this.getMetadataById(user.value.userId);
|
|
||||||
}),
|
|
||||||
pairwiseStartWith(undefined),
|
pairwiseStartWith(undefined),
|
||||||
map(([prev, curr]) => {
|
map(([prev, curr]) => {
|
||||||
if (prev?.state === 'success' && curr.state === 'loading') {
|
if (prev?.state === 'success' && curr.state === 'loading') {
|
||||||
@ -241,8 +213,8 @@ export class AuthUserDetailComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getMetadataById(userId: string): Observable<MetadataQuery> {
|
private getMetadata(): Observable<MetadataQuery> {
|
||||||
return defer(() => this.newMgmtService.listUserMetadata(userId)).pipe(
|
return defer(() => this.newAuthService.listMyMetadata()).pipe(
|
||||||
map((metadata) => ({ state: 'success', value: metadata.result }) as const),
|
map((metadata) => ({ state: 'success', value: metadata.result }) as const),
|
||||||
startWith({ state: 'loading', value: [] as Metadata[] } as const),
|
startWith({ state: 'loading', value: [] as Metadata[] } as const),
|
||||||
catchError((error) => of({ state: 'error', error } as const)),
|
catchError((error) => of({ state: 'error', error } as const)),
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { GrpcService } from './grpc.service';
|
import { GrpcService } from './grpc.service';
|
||||||
import { create } from '@bufbuild/protobuf';
|
|
||||||
import {
|
import {
|
||||||
AddMyAuthFactorOTPSMSRequestSchema,
|
|
||||||
AddMyAuthFactorOTPSMSResponse,
|
AddMyAuthFactorOTPSMSResponse,
|
||||||
GetMyUserRequestSchema,
|
|
||||||
GetMyUserResponse,
|
GetMyUserResponse,
|
||||||
VerifyMyPhoneRequestSchema,
|
ListMyMetadataResponse,
|
||||||
VerifyMyPhoneResponse,
|
VerifyMyPhoneResponse,
|
||||||
} from '@zitadel/proto/zitadel/auth_pb';
|
} from '@zitadel/proto/zitadel/auth_pb';
|
||||||
|
|
||||||
@ -17,14 +14,18 @@ export class NewAuthService {
|
|||||||
constructor(private readonly grpcService: GrpcService) {}
|
constructor(private readonly grpcService: GrpcService) {}
|
||||||
|
|
||||||
public getMyUser(): Promise<GetMyUserResponse> {
|
public getMyUser(): Promise<GetMyUserResponse> {
|
||||||
return this.grpcService.authNew.getMyUser(create(GetMyUserRequestSchema));
|
return this.grpcService.authNew.getMyUser({});
|
||||||
}
|
}
|
||||||
|
|
||||||
public verifyMyPhone(code: string): Promise<VerifyMyPhoneResponse> {
|
public verifyMyPhone(code: string): Promise<VerifyMyPhoneResponse> {
|
||||||
return this.grpcService.authNew.verifyMyPhone(create(VerifyMyPhoneRequestSchema, { code }));
|
return this.grpcService.authNew.verifyMyPhone({});
|
||||||
}
|
}
|
||||||
|
|
||||||
public addMyAuthFactorOTPSMS(): Promise<AddMyAuthFactorOTPSMSResponse> {
|
public addMyAuthFactorOTPSMS(): Promise<AddMyAuthFactorOTPSMSResponse> {
|
||||||
return this.grpcService.authNew.addMyAuthFactorOTPSMS(create(AddMyAuthFactorOTPSMSRequestSchema));
|
return this.grpcService.authNew.addMyAuthFactorOTPSMS({});
|
||||||
|
}
|
||||||
|
|
||||||
|
public listMyMetadata(): Promise<ListMyMetadataResponse> {
|
||||||
|
return this.grpcService.authNew.listMyMetadata({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user