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:
@ -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])
|
||||
}
|
||||
|
@ -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=<some-command-name>&groupId=<some-group-id>"
|
||||
*/
|
||||
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=<command-name>&groupId=<group-id>`
|
||||
*/
|
||||
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) {
|
||||
|
@ -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')
|
||||
|
Reference in New Issue
Block a user