diff --git a/src/hooks/useAuthNavigation.tsx b/src/hooks/useAuthNavigation.tsx index 6b337fc9c..91976081a 100644 --- a/src/hooks/useAuthNavigation.tsx +++ b/src/hooks/useAuthNavigation.tsx @@ -15,7 +15,6 @@ export function useAuthNavigation() { // Subscribe to the auth state of the app and navigate accordingly. useEffect(() => { - console.log('authState', authState.value) if ( authState.matches('loggedIn') && location.pathname.includes(PATHS.SIGN_IN) @@ -25,7 +24,7 @@ export function useAuthNavigation() { authState.matches('loggedOut') && !location.pathname.includes(PATHS.SIGN_IN) ) { - navigate(PATHS.SIGN_IN) + navigate(PATHS.SIGN_IN + (location.search || '')) } }, [authState, location.pathname]) } diff --git a/src/hooks/useQueryParamEffects.ts b/src/hooks/useQueryParamEffects.ts index f3f67e27d..1f6d22a9b 100644 --- a/src/hooks/useQueryParamEffects.ts +++ b/src/hooks/useQueryParamEffects.ts @@ -13,7 +13,7 @@ import { } from '@src/lib/constants' import { isDesktop } from '@src/lib/isDesktop' import type { FileLinkParams } from '@src/lib/links' -import { commandBarActor } from '@src/lib/singletons' +import { commandBarActor, useAuthState } from '@src/lib/singletons' import { showCodeReplaceToast } from '@src/components/CodeReplaceToast' import { findKclSample } from '@src/lib/kclSamples' import { webSafePathSplit } from '@src/lib/paths' @@ -34,6 +34,7 @@ export type CreateFileSchemaMethodOptional = Omit< * "?cmd=&groupId=" */ export function useQueryParamEffects() { + const authState = useAuthState() const [searchParams, setSearchParams] = useSearchParams() const shouldInvokeCreateFile = searchParams.has(CREATE_FILE_URL_PARAM) const shouldInvokeGenericCmd = @@ -44,7 +45,7 @@ export function useQueryParamEffects() { * Watches for legacy `?create-file` hook, which share links currently use. */ useEffect(() => { - if (shouldInvokeCreateFile) { + if (shouldInvokeCreateFile && authState.matches('loggedIn')) { const argDefaultValues = buildCreateFileCommandArgs(searchParams) commandBarActor.send({ type: 'Find and select command', @@ -59,14 +60,14 @@ export function useQueryParamEffects() { searchParams.delete(CREATE_FILE_URL_PARAM) setSearchParams(searchParams) } - }, [shouldInvokeCreateFile, setSearchParams]) + }, [shouldInvokeCreateFile, setSearchParams, authState]) /** * Generic commands are triggered by query parameters * with the pattern: `?cmd=&groupId=` */ useEffect(() => { - if (!shouldInvokeGenericCmd) return + if (!shouldInvokeGenericCmd || !authState.matches('loggedIn')) return const commandData = buildGenericCommandArgs(searchParams) if (!commandData) return @@ -166,7 +167,7 @@ export function useQueryParamEffects() { } setSearchParams(searchParams) } - }, [shouldInvokeGenericCmd, setSearchParams]) + }, [shouldInvokeGenericCmd, setSearchParams, authState]) } function buildCreateFileCommandArgs(searchParams: URLSearchParams) { diff --git a/src/routes/SignIn.tsx b/src/routes/SignIn.tsx index fd14429ef..23dcdeab0 100644 --- a/src/routes/SignIn.tsx +++ b/src/routes/SignIn.tsx @@ -59,7 +59,7 @@ const SignIn = () => { const signInDesktop = async () => { // We want to invoke our command to login via device auth. const userCodeToDisplay = await window.electron - .startDeviceFlow(VITE_KC_API_BASE_URL) + .startDeviceFlow(VITE_KC_API_BASE_URL + location.search) .catch(reportError) if (!userCodeToDisplay) { console.error('No user code received while trying to log in')