Skip to content

Commit

Permalink
Merge pull request #136 from CriticalMoments/ssr_redux
Browse files Browse the repository at this point in the history
Bit more auth checking.
  • Loading branch information
scosman authored Aug 30, 2024
2 parents d314ac0 + 574345d commit f6231b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/routes/(admin)/account/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const load: LayoutServerLoad = async ({
const { data: profile } = await supabase
.from("profiles")
.select(`*`)
.eq("id", user?.id)
.eq("id", user.id)
.single()

return { session, profile, cookies: cookies.getAll() }
return { session, user, profile, cookies: cookies.getAll() }
}
11 changes: 7 additions & 4 deletions src/routes/(admin)/account/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ export const load = async ({ fetch, data, depends, url }) => {
})

/**
* It's fine to use `getSession` here, because on the client, `getSession` is
* safe, and on the server, it reads `session` from the `LayoutData`, which
* safely checked the session using `safeGetSession`.
* Source: https://supabase.com/docs/guides/auth/server-side/sveltekit
* Not always safe on server, but calling getUser next to verify JWT token
*/
const {
data: { session },
Expand All @@ -52,7 +49,13 @@ export const load = async ({ fetch, data, depends, url }) => {
}
const {
data: { user },
error: userError,
} = await supabase.auth.getUser()
if (userError || !user) {
// JWT validation has failed
console.log("User error", userError)
redirect(303, "/login")
}

const { data: aal } = await supabase.auth.mfa.getAuthenticatorAssuranceLevel()

Expand Down

0 comments on commit f6231b8

Please sign in to comment.