diff --git a/packages/frontend/core/src/desktop/pages/404/index.tsx b/packages/frontend/core/src/desktop/pages/404/index.tsx
index 13ea86db8..ebcb7291e 100644
--- a/packages/frontend/core/src/desktop/pages/404/index.tsx
+++ b/packages/frontend/core/src/desktop/pages/404/index.tsx
@@ -5,6 +5,7 @@ import {
import { useSignOut } from '@affine/core/components/hooks/affine/use-sign-out';
import { DesktopApiService } from '@affine/core/modules/desktop-api';
import {
+ FrameworkScope,
useLiveData,
useService,
useServiceOptional,
@@ -16,7 +17,7 @@ import {
RouteLogic,
useNavigateHelper,
} from '../../../components/hooks/use-navigate-helper';
-import { AuthService } from '../../../modules/cloud';
+import { ServersService } from '../../../modules/cloud';
import { SignIn } from '../auth/sign-in';
/**
@@ -27,9 +28,15 @@ export const PageNotFound = ({
}: {
noPermission?: boolean;
}): ReactElement => {
- const authService = useService(AuthService);
+ const serversService = useService(ServersService);
+ const serversWithAccount = useLiveData(serversService.serversWithAccount$);
+
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 openSignOutModal = useSignOut();
@@ -46,19 +53,23 @@ export const PageNotFound = ({
// strip the origin
const currentUrl = window.location.href.replace(window.location.origin, '');
- return noPermission ? (
- }
- />
- ) : (
-
+ return (
+
+ {noPermission ? (
+ }
+ />
+ ) : (
+
+ )}
+
);
};
diff --git a/packages/frontend/core/src/modules/cloud/services/servers.ts b/packages/frontend/core/src/modules/cloud/services/servers.ts
index 757390d99..97bac0ae3 100644
--- a/packages/frontend/core/src/modules/cloud/services/servers.ts
+++ b/packages/frontend/core/src/modules/cloud/services/servers.ts
@@ -47,6 +47,17 @@ export class ServersService extends Service {
[] as any
);
+ serversWithAccount$ = this.servers$
+ .map(servers =>
+ servers.map(server =>
+ server.account$.map(account => ({
+ server,
+ account,
+ }))
+ )
+ )
+ .flat();
+
server$(id: string) {
return this.servers$.map(servers =>
servers.find(server => server.id === id)