-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from CriticalMoments/fix_redirect_loop
Fix a redirect loop.
- Loading branch information
Showing
6 changed files
with
63 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { isBrowser } from "@supabase/ssr" | ||
import type { Session, SupabaseClient } from "@supabase/supabase-js" | ||
import type { Database } from "../DatabaseDefinitions.js" | ||
|
||
export const load_helper = async ( | ||
server_session: Session | null, | ||
supabase: SupabaseClient<Database>, | ||
) => { | ||
// on server populated on server by LayoutData, using authGuard hook | ||
let session = server_session | ||
if (isBrowser()) { | ||
// Only call getSession in browser where it's safe. | ||
const getSessionResponse = await supabase.auth.getSession() | ||
session = getSessionResponse.data.session | ||
} | ||
if (!session) { | ||
return { | ||
session: null, | ||
user: null, | ||
} | ||
} | ||
|
||
// https://github.com/supabase/auth-js/issues/888#issuecomment-2189298518 | ||
if ("suppressGetSessionWarning" in supabase.auth) { | ||
// @ts-expect-error - suppressGetSessionWarning is not part of the official API | ||
supabase.auth.suppressGetSessionWarning = true | ||
} else { | ||
console.warn( | ||
"SupabaseAuthClient#suppressGetSessionWarning was removed. See https://github.com/supabase/auth-js/issues/888.", | ||
) | ||
} | ||
const { | ||
data: { user }, | ||
error: userError, | ||
} = await supabase.auth.getUser() | ||
if (userError || !user) { | ||
return { | ||
session: null, | ||
user: null, | ||
} | ||
} | ||
|
||
return { | ||
session, | ||
user, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,13 @@ | ||
import { redirect } from "@sveltejs/kit" | ||
import type { LayoutServerLoad } from "./$types" | ||
|
||
export const load: LayoutServerLoad = async ({ | ||
locals: { session }, | ||
cookies, | ||
url, | ||
}) => { | ||
// if the user is already logged in return them to the account page | ||
if (session) { | ||
redirect(303, "/account") | ||
} | ||
|
||
return { | ||
url: url.origin, | ||
cookies: cookies.getAll(), | ||
session, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters