Skip to content

Commit

Permalink
Merge upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sync Fork committed Jan 3, 2024
1 parent 9eacb17 commit 39ac213
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

0 comments on commit 39ac213

Please sign in to comment.