diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 9ebcd61d4e1..a6ed1cedcde 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -70,6 +70,7 @@ export const KCL_DEFAULT_COLOR = `#3c73ff` export const SETTINGS_FILE_NAME = 'settings.toml' export const PROJECT_SETTINGS_FILE_NAME = 'project.toml' export const COOKIE_NAME = '__Secure-next-auth.session-token' +export const COOKIE_NAME_DEV = '__Secure-session-token-dev' export const TELEMETRY_FILE_NAME = 'boot.txt' export const TELEMETRY_RAW_FILE_NAME = 'raw-metrics.txt' export const ENVIRONMENT_FILE_NAME = 'environment.txt' diff --git a/src/lib/promptToEdit.tsx b/src/lib/promptToEdit.tsx index cc5234de1f4..3224560b57e 100644 --- a/src/lib/promptToEdit.tsx +++ b/src/lib/promptToEdit.tsx @@ -4,8 +4,7 @@ import type { Models } from '@kittycad/lib' import { diffLines } from 'diff' import toast from 'react-hot-toast' import type { TextToCadMultiFileIteration_type } from '@kittycad/lib/dist/types/src/models' -import { getCookie, TOKEN_PERSIST_KEY } from '@src/machines/authMachine' -import { APP_DOWNLOAD_PATH, COOKIE_NAME } from '@src/lib/constants' +import { APP_DOWNLOAD_PATH } from '@src/lib/constants' import { isDesktop } from '@src/lib/isDesktop' import { openExternalBrowserIfDesktop } from '@src/lib/openWindow' import { ActionButton } from '@src/components/ActionButton' @@ -112,14 +111,9 @@ export async function submitPromptToEditToQueue({ selections: Selections | null projectFiles: FileMeta[] projectName: string - token?: string + token: string artifactGraph: ArtifactGraph }) { - const _token = - token && token !== '' - ? token - : getCookie(COOKIE_NAME) || localStorage?.getItem(TOKEN_PERSIST_KEY) || '' - const kclFilesMap: KclFileMetaMap = {} const endPointFiles: KittyCadLibFile[] = [] projectFiles.forEach((file) => { @@ -150,7 +144,7 @@ export async function submitPromptToEditToQueue({ kcl_version: kclManager.kclVersion, }, endPointFiles, - _token + token ) } @@ -328,7 +322,7 @@ export async function doPromptEdit({ prompt: string selections: Selections projectFiles: FileMeta[] - token?: string + token: string projectName: string artifactGraph: ArtifactGraph }): Promise { @@ -413,7 +407,7 @@ export async function promptToEditFlow({ prompt: string selections: Selections projectFiles: FileMeta[] - token?: string + token: string artifactGraph: ArtifactGraph projectName: string filePath: string | undefined diff --git a/src/machines/authMachine.ts b/src/machines/authMachine.ts index 0710beb7194..328aad2ba64 100644 --- a/src/machines/authMachine.ts +++ b/src/machines/authMachine.ts @@ -1,7 +1,12 @@ import type { Models } from '@kittycad/lib' import env, { updateEnvironment, updateEnvironmentPool } from '@src/env' import { assign, fromPromise, setup } from 'xstate' -import { COOKIE_NAME, OAUTH2_DEVICE_CLIENT_ID } from '@src/lib/constants' +import { + COOKIE_NAME, + COOKIE_NAME_DEV, + COOKIE_NAME_LEGACY, + OAUTH2_DEVICE_CLIENT_ID, +} from '@src/lib/constants' import { getUser as getUserDesktop, listAllEnvironments, @@ -223,11 +228,19 @@ async function getUser(input: { token?: string }) { } } -export function getCookie(cname: string): string | null { +export function getCookie(): string | null { if (isDesktop()) { return null } + if (window.electron.process.env.NODE_ENV === 'production') { + return getCookieByName(COOKIE_NAME) + } else { + return getCookieByName(COOKIE_NAME_DEV) + } +} + +function getCookieByName(cname: string): string | null { let name = cname + '=' let decodedCookie = decodeURIComponent(document.cookie) let ca = decodedCookie.split(';')