import { Injectable } from '@angular/core'; import { GrpcService } from './grpc.service'; import { create, MessageInitShape } from '@bufbuild/protobuf'; import { AddMyAuthFactorOTPSMSResponse, GetMyLoginPolicyResponse, GetMyLoginPolicyRequestSchema, GetMyPasswordComplexityPolicyResponse, ListMyAuthFactorsRequestSchema, ListMyAuthFactorsResponse, RemoveMyAuthFactorOTPEmailRequestSchema, RemoveMyAuthFactorOTPEmailResponse, RemoveMyAuthFactorOTPRequestSchema, RemoveMyAuthFactorOTPResponse, RemoveMyAuthFactorU2FRequestSchema, RemoveMyAuthFactorU2FResponse, RemoveMyAuthFactorOTPSMSRequestSchema, RemoveMyAuthFactorOTPSMSResponse, ListMyMetadataResponse, VerifyMyPhoneResponse, ListMyZitadelPermissionsResponse, ListMyProjectOrgsRequestSchema, } from '@zitadel/proto/zitadel/auth_pb'; import { injectQuery } from '@tanstack/angular-query-experimental'; import { UserService } from './user.service'; @Injectable({ providedIn: 'root', }) export class NewAuthService { constructor( private readonly grpcService: GrpcService, private readonly userService: UserService, ) {} public verifyMyPhone(code: string): Promise { return this.grpcService.authNew.verifyMyPhone({ code }); } public addMyAuthFactorOTPSMS(): Promise { return this.grpcService.authNew.addMyAuthFactorOTPSMS({}); } public listMyMetadata(): Promise { return this.grpcService.authNew.listMyMetadata({}); } public listMyMultiFactors(): Promise { return this.grpcService.authNew.listMyAuthFactors(create(ListMyAuthFactorsRequestSchema)); } public removeMyAuthFactorOTPSMS(): Promise { return this.grpcService.authNew.removeMyAuthFactorOTPSMS(create(RemoveMyAuthFactorOTPSMSRequestSchema)); } public getMyLoginPolicy(): Promise { return this.grpcService.authNew.getMyLoginPolicy(create(GetMyLoginPolicyRequestSchema)); } public removeMyMultiFactorOTP(): Promise { return this.grpcService.authNew.removeMyAuthFactorOTP(create(RemoveMyAuthFactorOTPRequestSchema)); } public removeMyMultiFactorU2F(tokenId: string): Promise { return this.grpcService.authNew.removeMyAuthFactorU2F(create(RemoveMyAuthFactorU2FRequestSchema, { tokenId })); } public removeMyAuthFactorOTPEmail(): Promise { return this.grpcService.authNew.removeMyAuthFactorOTPEmail(create(RemoveMyAuthFactorOTPEmailRequestSchema)); } public getMyPasswordComplexityPolicy(): Promise { return this.grpcService.authNew.getMyPasswordComplexityPolicy({}); } public listMyZitadelPermissions(): Promise { return this.grpcService.authNew.listMyZitadelPermissions({}); } public listMyZitadelPermissionsQuery() { return injectQuery(() => ({ queryKey: [this.userService.userId(), 'auth', 'listMyZitadelPermissions'], queryFn: () => this.listMyZitadelPermissions().then(({ result }) => result), })); } public listMyProjectOrgs(req: MessageInitShape, signal?: AbortSignal) { return this.grpcService.authNew.listMyProjectOrgs(req, { signal }); } }