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

@@ -41,6 +41,7 @@ import {
loadLastViewedChatFromStorage,
saveLastViewedChatToStorage
} from '../../infrastructure/persistence';
import { setStoredCurrentUserId } from '../../core/storage/current-user-storage';
import { AppI18nService } from '../../core/i18n';
import { ServerDirectoryFacade } from '../../domains/server-directory';
import { hasRoomBanForUser } from '../../domains/access-control';
@@ -219,6 +220,9 @@ export class RoomsEffects {
?? allEndpoints[0]
?? null;
const normalizedPassword = typeof password === 'string' ? password.trim() : '';
setStoredCurrentUserId(currentUser.id);
const room: Room = {
id: uuidv4(),
name,
@@ -237,35 +241,36 @@ export class RoomsEffects {
sourceUrl: endpoint?.url
};
// Save to local DB
this.db.saveRoom(room);
return from(this.db.saveRoom(room)).pipe(
map(() => {
// Register with central server (using the same room ID for discoverability)
this.serverDirectory
.registerServer({
id: room.id, // Use the same ID as the local room
name: room.name,
description: room.description,
ownerId: currentUser.id,
ownerPublicKey: currentUser.oderId,
hostName: currentUser.displayName,
password: normalizedPassword || null,
hasPassword: normalizedPassword.length > 0,
isPrivate: room.isPrivate,
userCount: room.userCount,
maxUsers: room.maxUsers || 50,
icon: room.icon,
iconUpdatedAt: room.iconUpdatedAt,
tags: [],
channels: room.channels ?? defaultChannels()
}, endpoint ? {
sourceId: endpoint.id,
sourceUrl: endpoint.url
} : undefined
)
.subscribe();
// Register with central server (using the same room ID for discoverability)
this.serverDirectory
.registerServer({
id: room.id, // Use the same ID as the local room
name: room.name,
description: room.description,
ownerId: currentUser.id,
ownerPublicKey: currentUser.oderId,
hostName: currentUser.displayName,
password: normalizedPassword || null,
hasPassword: normalizedPassword.length > 0,
isPrivate: room.isPrivate,
userCount: 1,
maxUsers: room.maxUsers || 50,
icon: room.icon,
iconUpdatedAt: room.iconUpdatedAt,
tags: [],
channels: room.channels ?? defaultChannels()
}, endpoint ? {
sourceId: endpoint.id,
sourceUrl: endpoint.url
} : undefined
)
.subscribe();
return of(RoomsActions.createRoomSuccess({ room }));
return RoomsActions.createRoomSuccess({ room });
})
);
}),
catchError((error) => of(RoomsActions.createRoomFailure({ error: error.message })))
)
@@ -303,6 +308,8 @@ export class RoomsEffects {
: undefined;
if (room) {
setStoredCurrentUserId(currentUser.id);
const resolvedSource = this.serverDirectory.normaliseRoomSignalSource({
sourceId: serverInfo?.sourceId ?? room.sourceId,
sourceName: serverInfo?.sourceName ?? room.sourceName,
@@ -329,7 +336,7 @@ export class RoomsEffects {
: (typeof room.hasPassword === 'boolean' ? room.hasPassword : !!room.password)
};
this.db.updateRoom(room.id, {
return from(this.db.updateRoom(room.id, {
sourceId: resolvedRoom.sourceId,
sourceName: resolvedRoom.sourceName,
sourceUrl: resolvedRoom.sourceUrl,
@@ -342,13 +349,13 @@ export class RoomsEffects {
iconUpdatedAt: resolvedRoom.iconUpdatedAt,
hasPassword: resolvedRoom.hasPassword,
isPrivate: resolvedRoom.isPrivate
});
return of(RoomsActions.joinRoomSuccess({ room: resolvedRoom }));
})).pipe(map(() => RoomsActions.joinRoomSuccess({ room: resolvedRoom })));
}
// If not in local DB but we have server info from search, create a room entry
if (serverInfo) {
setStoredCurrentUserId(currentUser.id);
const resolvedSource = this.serverDirectory.normaliseRoomSignalSource({
sourceId: serverInfo.sourceId,
sourceName: serverInfo.sourceName,
@@ -378,15 +385,17 @@ export class RoomsEffects {
...resolvedSource
};
// Save to local DB for future reference
this.db.saveRoom(newRoom);
return of(RoomsActions.joinRoomSuccess({ room: newRoom }));
return from(this.db.saveRoom(newRoom)).pipe(
map(() => RoomsActions.joinRoomSuccess({ room: newRoom }))
);
}
// Try to get room info from server
return this.serverDirectory.getServer(roomId, sourceSelector).pipe(
switchMap((serverData) => {
if (serverData) {
setStoredCurrentUserId(currentUser.id);
const resolvedSource = this.serverDirectory.normaliseRoomSignalSource({
sourceId: serverData.sourceId,
sourceName: serverData.sourceName,
@@ -415,8 +424,9 @@ export class RoomsEffects {
...resolvedSource
};
this.db.saveRoom(newRoom);
return of(RoomsActions.joinRoomSuccess({ room: newRoom }));
return from(this.db.saveRoom(newRoom)).pipe(
map(() => RoomsActions.joinRoomSuccess({ room: newRoom }))
);
}
return of(RoomsActions.joinRoomFailure({ error: this.i18n.instant('servers.errors.roomNotFound') }));