Skip to content

Commit

Permalink
Merge pull request #2437 from nhost/fix/sveltekit-quickstart
Browse files Browse the repository at this point in the history
fix(quickstarts): fix auth issue and too many redirects error
  • Loading branch information
onehassan committed Jan 2, 2024
2 parents e9d5d0a + b4dccd4 commit cef1167
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-donuts-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@nhost-examples/sveltekit': patch
---

fix: resolve auth issue and too many redirects error
8 changes: 6 additions & 2 deletions examples/quickstarts/sveltekit/src/lib/nhost.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ export const NHOST_SESSION_KEY = 'nhostSession';
/** @param {import('@sveltejs/kit').Cookies} cookies */
export const getNhost = async (cookies) => {

/** @type {import('@nhost/nhost-js').NhostClient} */
const nhost = new NhostClient({
subdomain: env.PUBLIC_NHOST_SUBDOMAIN || 'local',
region: env.PUBLIC_NHOST_REGION,
region: env.PUBLIC_NHOST_REGION,
clientStorageType: 'cookie',
start: false
})

const sessionCookieValue = cookies.get(NHOST_SESSION_KEY) || ''

/** @type {import('@nhost/nhost-js').NhostSession} */
const initialSession = JSON.parse(atob(sessionCookieValue) || 'null')

nhost.auth.client.start({ initialSession })

/** @type {import('@nhost/nhost-js').NhostSession} */
Expand Down Expand Up @@ -50,6 +52,8 @@ export const manageAuthSession = async (
const { session: newSession, error } = await nhost.auth.refreshSession(refreshToken)

if (error) {
// delete session cookie when the refreshToken has expired
event.cookies.delete(NHOST_SESSION_KEY, { path: '/' })
return onError?.(error)
}

Expand Down

1 comment on commit cef1167

@vercel
Copy link

@vercel vercel bot commented on cef1167 Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs/

docs-git-main-nhost.vercel.app
docs-nhost.vercel.app

Please sign in to comment.