mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-19 19:48:45 +00:00
feat(console): rehauled navigation for instances including breadcrumb (#10283)
This PR significantly improves user navigation by introducing a new instance-level navigation bar. This new bar, positioned above the existing organization navigation, provides quick access to key sections: Home, Organizations, Actions, and Settings. Additionally, the breadcrumb component has been refined for more consistent behavior, reintroducing intuitive breadcrumb buttons to easily navigate up the hierarchy. These changes also include design improvements for a cleaner and more streamlined appearance across the interface. <img width="423" height="138" alt="Screenshot 2025-07-17 at 14 55 46" src="https://github.com/user-attachments/assets/ba9e40a1-1077-4cb6-8735-ac7ab637abe7" /> <img width="562" height="132" alt="Screenshot 2025-07-17 at 14 56 41" src="https://github.com/user-attachments/assets/d85dc673-0df8-4677-9d2b-dc031dde42c3" /> <img width="545" height="254" alt="Screenshot 2025-07-17 at 14 56 10" src="https://github.com/user-attachments/assets/eaf10117-079e-4181-8dbb-60c89b24556a" /> <img width="689" height="261" alt="Screenshot 2025-07-17 at 14 56 20" src="https://github.com/user-attachments/assets/510ad550-1d9a-4c6a-8af1-66cb0b23619c" /> --------- Co-authored-by: conblem <[email protected]> Co-authored-by: Stefan Benz <[email protected]> Co-authored-by: Florian Forster <[email protected]>
This commit is contained in:
co-authored by
conblem
Stefan Benz
Florian Forster
parent
cccba3f8f3
commit
f963ea9f86
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { computed, Injectable, Signal } from '@angular/core';
|
||||
import { GrpcService } from './grpc.service';
|
||||
import {
|
||||
AddHumanUserRequestSchema,
|
||||
@@ -18,9 +18,6 @@ import {
|
||||
ListPasskeysResponse,
|
||||
ListUsersRequestSchema,
|
||||
ListUsersResponse,
|
||||
LockUserRequestSchema,
|
||||
LockUserResponse,
|
||||
PasswordResetRequestSchema,
|
||||
ReactivateUserRequestSchema,
|
||||
ReactivateUserResponse,
|
||||
RemoveOTPEmailRequestSchema,
|
||||
@@ -49,84 +46,85 @@ import {
|
||||
UpdateHumanUserResponse,
|
||||
} from '@zitadel/proto/zitadel/user/v2/user_service_pb';
|
||||
import type { MessageInitShape } from '@bufbuild/protobuf';
|
||||
import {
|
||||
AccessTokenType,
|
||||
Gender,
|
||||
HumanProfile,
|
||||
HumanProfileSchema,
|
||||
HumanUser,
|
||||
HumanUserSchema,
|
||||
MachineUser,
|
||||
MachineUserSchema,
|
||||
User as UserV2,
|
||||
UserSchema,
|
||||
UserState,
|
||||
} from '@zitadel/proto/zitadel/user/v2/user_pb';
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import { Timestamp as TimestampV2, TimestampSchema } from '@bufbuild/protobuf/wkt';
|
||||
import { Details, DetailsSchema } from '@zitadel/proto/zitadel/object/v2/object_pb';
|
||||
import { Human, Machine, Phone, Profile, User } from '../proto/generated/zitadel/user_pb';
|
||||
import { ObjectDetails } from '../proto/generated/zitadel/object_pb';
|
||||
import { Timestamp } from '../proto/generated/google/protobuf/timestamp_pb';
|
||||
import { HumanPhone, HumanPhoneSchema } from '@zitadel/proto/zitadel/user/v2/phone_pb';
|
||||
import { OAuthService } from 'angular-oauth2-oidc';
|
||||
import { debounceTime, EMPTY, Observable, of, ReplaySubject, shareReplay, switchAll, switchMap } from 'rxjs';
|
||||
import { catchError, filter, map, startWith } from 'rxjs/operators';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { injectQuery, queryOptions, skipToken } from '@tanstack/angular-query-experimental';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UserService {
|
||||
private user$$ = new ReplaySubject<Observable<UserV2>>(1);
|
||||
public user$ = this.user$$.pipe(
|
||||
startWith(this.getUser()),
|
||||
// makes sure if many subscribers reset the observable only one wins
|
||||
debounceTime(10),
|
||||
switchAll(),
|
||||
catchError((err) => {
|
||||
// reset user observable on error
|
||||
this.user$$.next(this.getUser());
|
||||
throw err;
|
||||
}),
|
||||
);
|
||||
private readonly payload: Signal<unknown | undefined>;
|
||||
public readonly userId: Signal<string | undefined>;
|
||||
public readonly isExpired: Signal<boolean>;
|
||||
|
||||
public userQuery() {
|
||||
return injectQuery(() => this.userQueryOptions());
|
||||
}
|
||||
|
||||
public userQueryOptions() {
|
||||
const userId = this.userId();
|
||||
return queryOptions({
|
||||
queryKey: [userId, 'user'],
|
||||
queryFn: userId ? () => this.getUserById(userId).then((resp) => resp.user) : skipToken,
|
||||
});
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly grpcService: GrpcService,
|
||||
private readonly oauthService: OAuthService,
|
||||
) {}
|
||||
|
||||
private getUserId() {
|
||||
return this.oauthService.events.pipe(
|
||||
filter((event) => event.type === 'token_received'),
|
||||
map(() => this.oauthService.getIdToken()),
|
||||
startWith(this.oauthService.getIdToken()),
|
||||
filter(Boolean),
|
||||
switchMap((token) => {
|
||||
// we do this in a try catch so the observable will retry this logic if it fails
|
||||
try {
|
||||
// split jwt and get base64 encoded payload
|
||||
const unparsedPayload = atob(token.split('.')[1]);
|
||||
// parse payload
|
||||
const payload: unknown = JSON.parse(unparsedPayload);
|
||||
// check if sub is in payload and is a string
|
||||
if (payload && typeof payload === 'object' && 'sub' in payload && typeof payload.sub === 'string') {
|
||||
return of(payload.sub);
|
||||
}
|
||||
return EMPTY;
|
||||
} catch {
|
||||
return EMPTY;
|
||||
}
|
||||
}),
|
||||
);
|
||||
) {
|
||||
this.payload = this.getPayload();
|
||||
this.userId = this.getUserId(this.payload);
|
||||
this.isExpired = this.getIsExpired(this.payload);
|
||||
}
|
||||
|
||||
private getUser() {
|
||||
return this.getUserId().pipe(
|
||||
switchMap((id) => this.getUserById(id)),
|
||||
map((resp) => resp.user),
|
||||
filter(Boolean),
|
||||
shareReplay({ refCount: true, bufferSize: 1 }),
|
||||
private getPayload() {
|
||||
const idToken$ = this.oauthService.events.pipe(
|
||||
filter((event) => event.type === 'token_received'),
|
||||
// can actually return null
|
||||
// https://github.com/manfredsteyer/angular-oauth2-oidc/blob/c724ad73eadbb28338b084e3afa5ed49a0ea058c/projects/lib/src/oauth-service.ts#L2365
|
||||
map(() => this.oauthService.getIdToken() as string | null),
|
||||
);
|
||||
const idToken = toSignal(idToken$, { initialValue: this.oauthService.getIdToken() as string | null });
|
||||
|
||||
return computed(() => {
|
||||
try {
|
||||
// split jwt and get base64 encoded payload
|
||||
const unparsedPayload = atob((idToken() ?? '').split('.')[1]);
|
||||
// parse payload
|
||||
return JSON.parse(unparsedPayload) as unknown;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getUserId(payloadSignal: Signal<unknown | undefined>) {
|
||||
return computed(() => {
|
||||
const payload = payloadSignal();
|
||||
if (payload && typeof payload === 'object' && 'sub' in payload && typeof payload.sub === 'string') {
|
||||
return payload.sub;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
private getIsExpired(payloadSignal: Signal<unknown | undefined>) {
|
||||
const expSignal = computed(() => {
|
||||
const payload = payloadSignal();
|
||||
if (payload && typeof payload === 'object' && 'exp' in payload && typeof payload.exp === 'number') {
|
||||
return new Date(payload.exp * 1000);
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
return computed(() => {
|
||||
const exp = expSignal();
|
||||
return exp ? exp <= new Date() : true;
|
||||
});
|
||||
}
|
||||
|
||||
public addHumanUser(req: MessageInitShape<typeof AddHumanUserRequestSchema>): Promise<AddHumanUserResponse> {
|
||||
@@ -157,10 +155,6 @@ export class UserService {
|
||||
return this.grpcService.userNew.updateHumanUser(create(UpdateHumanUserRequestSchema, req));
|
||||
}
|
||||
|
||||
public lockUser(userId: string): Promise<LockUserResponse> {
|
||||
return this.grpcService.userNew.lockUser(create(LockUserRequestSchema, { userId }));
|
||||
}
|
||||
|
||||
public unlockUser(userId: string): Promise<UnlockUserResponse> {
|
||||
return this.grpcService.userNew.unlockUser(create(UnlockUserRequestSchema, { userId }));
|
||||
}
|
||||
@@ -221,10 +215,6 @@ export class UserService {
|
||||
return this.grpcService.userNew.createInviteCode(create(CreateInviteCodeRequestSchema, req));
|
||||
}
|
||||
|
||||
public passwordReset(req: MessageInitShape<typeof PasswordResetRequestSchema>) {
|
||||
return this.grpcService.userNew.passwordReset(create(PasswordResetRequestSchema, req));
|
||||
}
|
||||
|
||||
public setPassword(req: MessageInitShape<typeof SetPasswordRequestSchema>): Promise<SetPasswordResponse> {
|
||||
return this.grpcService.userNew.setPassword(create(SetPasswordRequestSchema, req));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user