Pass the query parameters through to sign-in flow (#7157)

* Pass the query parameters through to sign-in flow

So users can return to their invoked command after signing in

* Don't run query param commands if not logged in
This commit is contained in:
Frank Noirot
2025-05-21 11:32:52 -04:00
committed by GitHub
parent 5976a0cba6
commit d90d445d84
3 changed files with 8 additions and 8 deletions

View File

@ -15,7 +15,6 @@ export function useAuthNavigation() {
// Subscribe to the auth state of the app and navigate accordingly. // Subscribe to the auth state of the app and navigate accordingly.
useEffect(() => { useEffect(() => {
console.log('authState', authState.value)
if ( if (
authState.matches('loggedIn') && authState.matches('loggedIn') &&
location.pathname.includes(PATHS.SIGN_IN) location.pathname.includes(PATHS.SIGN_IN)
@ -25,7 +24,7 @@ export function useAuthNavigation() {
authState.matches('loggedOut') && authState.matches('loggedOut') &&
!location.pathname.includes(PATHS.SIGN_IN) !location.pathname.includes(PATHS.SIGN_IN)
) { ) {
navigate(PATHS.SIGN_IN) navigate(PATHS.SIGN_IN + (location.search || ''))
} }
}, [authState, location.pathname]) }, [authState, location.pathname])
} }

View File

@ -13,7 +13,7 @@ import {
} from '@src/lib/constants' } from '@src/lib/constants'
import { isDesktop } from '@src/lib/isDesktop' import { isDesktop } from '@src/lib/isDesktop'
import type { FileLinkParams } from '@src/lib/links' 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 { showCodeReplaceToast } from '@src/components/CodeReplaceToast'
import { findKclSample } from '@src/lib/kclSamples' import { findKclSample } from '@src/lib/kclSamples'
import { webSafePathSplit } from '@src/lib/paths' import { webSafePathSplit } from '@src/lib/paths'
@ -34,6 +34,7 @@ export type CreateFileSchemaMethodOptional = Omit<
* "?cmd=<some-command-name>&groupId=<some-group-id>" * "?cmd=<some-command-name>&groupId=<some-group-id>"
*/ */
export function useQueryParamEffects() { export function useQueryParamEffects() {
const authState = useAuthState()
const [searchParams, setSearchParams] = useSearchParams() const [searchParams, setSearchParams] = useSearchParams()
const shouldInvokeCreateFile = searchParams.has(CREATE_FILE_URL_PARAM) const shouldInvokeCreateFile = searchParams.has(CREATE_FILE_URL_PARAM)
const shouldInvokeGenericCmd = const shouldInvokeGenericCmd =
@ -44,7 +45,7 @@ export function useQueryParamEffects() {
* Watches for legacy `?create-file` hook, which share links currently use. * Watches for legacy `?create-file` hook, which share links currently use.
*/ */
useEffect(() => { useEffect(() => {
if (shouldInvokeCreateFile) { if (shouldInvokeCreateFile && authState.matches('loggedIn')) {
const argDefaultValues = buildCreateFileCommandArgs(searchParams) const argDefaultValues = buildCreateFileCommandArgs(searchParams)
commandBarActor.send({ commandBarActor.send({
type: 'Find and select command', type: 'Find and select command',
@ -59,14 +60,14 @@ export function useQueryParamEffects() {
searchParams.delete(CREATE_FILE_URL_PARAM) searchParams.delete(CREATE_FILE_URL_PARAM)
setSearchParams(searchParams) setSearchParams(searchParams)
} }
}, [shouldInvokeCreateFile, setSearchParams]) }, [shouldInvokeCreateFile, setSearchParams, authState])
/** /**
* Generic commands are triggered by query parameters * Generic commands are triggered by query parameters
* with the pattern: `?cmd=<command-name>&groupId=<group-id>` * with the pattern: `?cmd=<command-name>&groupId=<group-id>`
*/ */
useEffect(() => { useEffect(() => {
if (!shouldInvokeGenericCmd) return if (!shouldInvokeGenericCmd || !authState.matches('loggedIn')) return
const commandData = buildGenericCommandArgs(searchParams) const commandData = buildGenericCommandArgs(searchParams)
if (!commandData) return if (!commandData) return
@ -166,7 +167,7 @@ export function useQueryParamEffects() {
} }
setSearchParams(searchParams) setSearchParams(searchParams)
} }
}, [shouldInvokeGenericCmd, setSearchParams]) }, [shouldInvokeGenericCmd, setSearchParams, authState])
} }
function buildCreateFileCommandArgs(searchParams: URLSearchParams) { function buildCreateFileCommandArgs(searchParams: URLSearchParams) {

View File

@ -59,7 +59,7 @@ const SignIn = () => {
const signInDesktop = async () => { const signInDesktop = async () => {
// We want to invoke our command to login via device auth. // We want to invoke our command to login via device auth.
const userCodeToDisplay = await window.electron const userCodeToDisplay = await window.electron
.startDeviceFlow(VITE_KC_API_BASE_URL) .startDeviceFlow(VITE_KC_API_BASE_URL + location.search)
.catch(reportError) .catch(reportError)
if (!userCodeToDisplay) { if (!userCodeToDisplay) {
console.error('No user code received while trying to log in') console.error('No user code received while trying to log in')