From cc3749413a8efd51d23fd5d1833858d86ad7d609 Mon Sep 17 00:00:00 2001 From: Sumanth Chinthagunta Date: Thu, 27 Jun 2024 04:07:31 -0700 Subject: [PATCH] fix(console): save client side session into cookie after webauthn, and also use it with houdini --- apps/console/src/lib/graphql/client.ts | 4 ++-- apps/console/src/routes/(auth)/signin/+page.svelte | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/console/src/lib/graphql/client.ts b/apps/console/src/lib/graphql/client.ts index 18591449..346072fe 100644 --- a/apps/console/src/lib/graphql/client.ts +++ b/apps/console/src/lib/graphql/client.ts @@ -4,11 +4,11 @@ import { env } from '$env/dynamic/public'; import { HoudiniClient } from '$houdini'; import type { ClientPlugin } from '$houdini'; import { subscription } from '$houdini/plugins'; -import { accessToken as $accessToken } from '$lib/stores/user' -import { get } from 'svelte/store'; +import { accessToken as $accessToken } from '$lib/stores/user'; import { Logger, hasErrorMessage, hasErrorTypes, isErrorType } from '@spectacular/utils'; import { error, redirect } from '@sveltejs/kit'; import { createClient as createWSClient } from 'graphql-ws'; +import { get } from 'svelte/store'; const url = env.PUBLIC_GRAPHQL_ENDPOINT; diff --git a/apps/console/src/routes/(auth)/signin/+page.svelte b/apps/console/src/routes/(auth)/signin/+page.svelte index 0e7b3a69..2aee1115 100644 --- a/apps/console/src/routes/(auth)/signin/+page.svelte +++ b/apps/console/src/routes/(auth)/signin/+page.svelte @@ -3,6 +3,7 @@ import { goto } from '$app/navigation'; import { page } from '$app/stores'; import * as m from '$i18n/messages'; import { handleMessage } from '$lib/components/layout/toast-manager'; +import { NHOST_SESSION_KEY } from '$lib/constants.js'; import { pwSchema, pwlSchema } from '$lib/schema/user'; import { isLoadingForm } from '$lib/stores/loading'; import { nhost } from '$lib/stores/user'; @@ -10,13 +11,12 @@ import { getToastStore } from '@skeletonlabs/skeleton'; import { DebugShell } from '@spectacular/skeleton/components'; import { Icon } from '@spectacular/skeleton/components/icons'; import { Logger } from '@spectacular/utils'; +import Cookies from 'js-cookie'; // import { SiGithub } from "@icons-pack/svelte-simple-icons"; import { AlertTriangle, Fingerprint, Github, Loader, Mail, MoreHorizontal } from 'lucide-svelte'; import { fade } from 'svelte/transition'; import SuperDebug, { superForm } from 'sveltekit-superforms'; import { zodClient } from 'sveltekit-superforms/adapters'; -import Cookies from 'js-cookie' - import { NHOST_SESSION_KEY } from '$lib/constants.js'; export let data; const log = new Logger('auth:signin:browser'); @@ -96,10 +96,10 @@ async function waSignin() { const { session, error: signInError } = await nhost.auth.signIn({ email: $pwlForm.email, securityKey: true }); if (session) { Cookies.set(NHOST_SESSION_KEY, btoa(JSON.stringify(session)), { - path: '/', - sameSite: 'strict' - }) - goto('/dashboard'); + path: '/', + sameSite: 'strict', + }); + goto('/dashboard'); } else { console.log(signInError); }