Skip to content

Commit 54371df

Browse files
committed
In global layout SSR load, prevent whoami calls if no auth cookie is present
1 parent 0a144f1 commit 54371df

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/routes/+layout.server.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FRACTAL_SERVER_HOST } from '$env/static/private'
22
import { whoami } from '$lib/server/api/v1/auth_api'
33

4-
export async function load({ fetch }) {
4+
export async function load({ fetch, cookies }) {
55
// This is a mark to notify and log when the server is running SSR
66
console.log('SSR - Main layout')
77

@@ -16,6 +16,17 @@ export async function load({ fetch }) {
1616
console.error(error)
1717
})
1818

19+
// Check user info
20+
// Check auth cookie is present
21+
const fastApiUsersAuth = cookies.get('fastapiusersauth')
22+
if (!fastApiUsersAuth) {
23+
console.log('No auth cookie found')
24+
return {
25+
serverInfo,
26+
userInfo: null
27+
}
28+
}
29+
1930
const userInfo = await whoami(fetch)
2031
.catch(error => {
2132
console.log('Error loading user info')

0 commit comments

Comments
 (0)