diff --git a/apps/core/src/pages/desktop-signin.tsx b/apps/core/src/pages/desktop-signin.tsx index de957fffe2..f258fc16f2 100644 --- a/apps/core/src/pages/desktop-signin.tsx +++ b/apps/core/src/pages/desktop-signin.tsx @@ -1,7 +1,8 @@ -import type { LoaderFunction } from 'react-router-dom'; +import { getSession } from 'next-auth/react'; +import { type LoaderFunction } from 'react-router-dom'; import { z } from 'zod'; -import { signInCloud } from '../utils/cloud-utils'; +import { signInCloud, signOutCloud } from '../utils/cloud-utils'; const supportedProvider = z.enum(['google']); @@ -13,6 +14,16 @@ export const loader: LoaderFunction = async ({ request }) => { if (!callback_url) { return null; } + + const session = await getSession(); + + if (session) { + // already signed in, need to sign out first + await signOutCloud({ + callbackUrl: request.url, // retry + }); + } + const maybeProvider = supportedProvider.safeParse(provider); if (maybeProvider.success) { const provider = maybeProvider.data; diff --git a/apps/core/src/pages/open-app.tsx b/apps/core/src/pages/open-app.tsx index f452d6b165..00d828af9d 100644 --- a/apps/core/src/pages/open-app.tsx +++ b/apps/core/src/pages/open-app.tsx @@ -57,7 +57,7 @@ interface OpenAppProps { } interface LoaderData { - action: 'url' | 'oauth-jwt'; + action: 'url' | 'signin-redirect'; currentUser?: GetCurrentUserQuery['currentUser']; } @@ -86,12 +86,7 @@ const OpenAppImpl = ({ urlToOpen, channel }: OpenAppProps) => { return (