fix(core): avoid infinite sign in with selfhost (#13169)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * The 404 page now reflects user session state across multiple servers, showing the appropriate user context when multiple accounts are logged in. * **Improvements** * Enhanced user experience on the 404 page by accurately displaying information based on the first active logged-in account across all servers. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
import { useSignOut } from '@affine/core/components/hooks/affine/use-sign-out';
|
import { useSignOut } from '@affine/core/components/hooks/affine/use-sign-out';
|
||||||
import { DesktopApiService } from '@affine/core/modules/desktop-api';
|
import { DesktopApiService } from '@affine/core/modules/desktop-api';
|
||||||
import {
|
import {
|
||||||
|
FrameworkScope,
|
||||||
useLiveData,
|
useLiveData,
|
||||||
useService,
|
useService,
|
||||||
useServiceOptional,
|
useServiceOptional,
|
||||||
@@ -16,7 +17,7 @@ import {
|
|||||||
RouteLogic,
|
RouteLogic,
|
||||||
useNavigateHelper,
|
useNavigateHelper,
|
||||||
} from '../../../components/hooks/use-navigate-helper';
|
} from '../../../components/hooks/use-navigate-helper';
|
||||||
import { AuthService } from '../../../modules/cloud';
|
import { ServersService } from '../../../modules/cloud';
|
||||||
import { SignIn } from '../auth/sign-in';
|
import { SignIn } from '../auth/sign-in';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,9 +28,15 @@ export const PageNotFound = ({
|
|||||||
}: {
|
}: {
|
||||||
noPermission?: boolean;
|
noPermission?: boolean;
|
||||||
}): ReactElement => {
|
}): ReactElement => {
|
||||||
const authService = useService(AuthService);
|
const serversService = useService(ServersService);
|
||||||
|
const serversWithAccount = useLiveData(serversService.serversWithAccount$);
|
||||||
|
|
||||||
const desktopApi = useServiceOptional(DesktopApiService);
|
const desktopApi = useServiceOptional(DesktopApiService);
|
||||||
const account = useLiveData(authService.session.account$);
|
|
||||||
|
// Check all servers for any logged in accounts to avoid showing sign-in page if user has an active session on any server
|
||||||
|
const firstLogged = serversWithAccount.find(
|
||||||
|
({ account }) => account !== null
|
||||||
|
);
|
||||||
const { jumpToIndex } = useNavigateHelper();
|
const { jumpToIndex } = useNavigateHelper();
|
||||||
const openSignOutModal = useSignOut();
|
const openSignOutModal = useSignOut();
|
||||||
|
|
||||||
@@ -46,19 +53,23 @@ export const PageNotFound = ({
|
|||||||
// strip the origin
|
// strip the origin
|
||||||
const currentUrl = window.location.href.replace(window.location.origin, '');
|
const currentUrl = window.location.href.replace(window.location.origin, '');
|
||||||
|
|
||||||
return noPermission ? (
|
return (
|
||||||
|
<FrameworkScope scope={firstLogged?.server.scope}>
|
||||||
|
{noPermission ? (
|
||||||
<NoPermissionOrNotFound
|
<NoPermissionOrNotFound
|
||||||
user={account}
|
user={firstLogged?.account}
|
||||||
onBack={handleBackButtonClick}
|
onBack={handleBackButtonClick}
|
||||||
onSignOut={openSignOutModal}
|
onSignOut={openSignOutModal}
|
||||||
signInComponent={<SignIn redirectUrl={currentUrl} />}
|
signInComponent={<SignIn redirectUrl={currentUrl} />}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<NotFoundPage
|
<NotFoundPage
|
||||||
user={account}
|
user={firstLogged?.account}
|
||||||
onBack={handleBackButtonClick}
|
onBack={handleBackButtonClick}
|
||||||
onSignOut={openSignOutModal}
|
onSignOut={openSignOutModal}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
</FrameworkScope>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,17 @@ export class ServersService extends Service {
|
|||||||
[] as any
|
[] as any
|
||||||
);
|
);
|
||||||
|
|
||||||
|
serversWithAccount$ = this.servers$
|
||||||
|
.map(servers =>
|
||||||
|
servers.map(server =>
|
||||||
|
server.account$.map(account => ({
|
||||||
|
server,
|
||||||
|
account,
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.flat();
|
||||||
|
|
||||||
server$(id: string) {
|
server$(id: string) {
|
||||||
return this.servers$.map(servers =>
|
return this.servers$.map(servers =>
|
||||||
servers.find(server => server.id === id)
|
servers.find(server => server.id === id)
|
||||||
|
|||||||
Reference in New Issue
Block a user