fix: Fix multiple bugs with new authentication flow

This commit is contained in:
2026-06-07 15:04:21 +02:00
parent 9fc26b1ccf
commit 83456c018c
137 changed files with 4710 additions and 281 deletions

View File

@@ -54,6 +54,7 @@ import { findRoomMember, removeRoomMember } from '../rooms/room-members.helpers'
import { AppI18nService } from '../../core/i18n';
import { AuthTokenStoreService } from '../../domains/authentication/application/services/auth-token-store.service';
import { hasValidPersistedSession, SESSION_EXPIRED_ERROR_CODE } from '../../domains/authentication/domain/logic/auth-session.rules';
import { buildLoginReturnQueryParams } from '../../domains/authentication/domain/logic/auth-navigation.rules';
type IncomingModerationExtraAction =
| ReturnType<typeof RoomsActions.forgetRoom>
@@ -80,7 +81,7 @@ export class UsersEffects {
this.actions$.pipe(
ofType(UsersActions.authenticateUser),
switchMap(({ user }) =>
from(this.prepareAuthenticatedUserStorage(user.id)).pipe(
from(this.prepareAuthenticatedUserStorage(user)).pipe(
mergeMap(() => [
MessagesActions.clearMessages(),
UsersActions.resetUsersState(),
@@ -165,10 +166,11 @@ export class UsersEffects {
};
}
private async prepareAuthenticatedUserStorage(userId: string): Promise<void> {
setStoredCurrentUserId(userId);
private async prepareAuthenticatedUserStorage(user: User): Promise<void> {
setStoredCurrentUserId(user.id);
await this.db.initialize();
await this.db.setCurrentUserId(userId);
await this.db.setCurrentUserId(user.id);
await this.db.saveUser(user);
}
/** Loads all users associated with a specific room from the local database. */
@@ -476,6 +478,7 @@ export class UsersEffects {
withLatestFrom(this.store.select(selectCurrentUser)),
tap(([, user]) => {
if (user) {
setStoredCurrentUserId(user.id);
this.db.saveUser(user);
// Ensure current user ID is persisted when explicitly set
this.db.setCurrentUserId(user.id);
@@ -491,12 +494,16 @@ export class UsersEffects {
this.actions$.pipe(
ofType(UsersActions.loadCurrentUserFailure),
filter(({ error }) => error === SESSION_EXPIRED_ERROR_CODE),
tap(() => {
withLatestFrom(this.store.select(selectCurrentUser)),
tap(([, currentUser]) => {
if (currentUser) {
setStoredCurrentUserId(currentUser.id);
return;
}
clearStoredCurrentUserId();
void this.router.navigate(['/login'], {
queryParams: {
returnUrl: this.router.url
}
queryParams: buildLoginReturnQueryParams(this.router.url)
});
})
),

View File

@@ -518,6 +518,7 @@ export const usersReducer = createReducer(
};
const hasRoomId = Object.prototype.hasOwnProperty.call(voiceState, 'roomId');
const hasServerId = Object.prototype.hasOwnProperty.call(voiceState, 'serverId');
const hasClientInstanceId = Object.prototype.hasOwnProperty.call(voiceState, 'clientInstanceId');
return usersAdapter.updateOne(
{
@@ -531,7 +532,8 @@ export const usersReducer = createReducer(
isMutedByAdmin: voiceState.isMutedByAdmin ?? prev.isMutedByAdmin,
volume: voiceState.volume ?? prev.volume,
roomId: hasRoomId ? voiceState.roomId : prev.roomId,
serverId: hasServerId ? voiceState.serverId : prev.serverId
serverId: hasServerId ? voiceState.serverId : prev.serverId,
clientInstanceId: hasClientInstanceId ? voiceState.clientInstanceId : prev.clientInstanceId
}
}
},