Skip to content

Commit da2551d

Browse files
committed
better logging
1 parent 029dadf commit da2551d

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

src/hooks.server.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type Handle, redirect } from "@sveltejs/kit"
22
import { createServerClient } from "@supabase/ssr"
33
import { sequence } from "@sveltejs/kit/hooks"
4-
import { PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY } from "$env/static/public"
4+
import { PUBLIC_SUPABASE_ANON_KEY, PUBLIC_LOCAL_SUPABASE_URL } from "$env/static/public"
55
import type { Database } from "$lib/types/supabase"
66

77
const redirects: Handle = async ({ event, resolve }) => {
@@ -21,22 +21,27 @@ const redirects: Handle = async ({ event, resolve }) => {
2121
}
2222

2323
const supabase: Handle = async ({ event, resolve }) => {
24-
event.locals.supabaseServer = createServerClient<Database>(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
25-
cookies: {
26-
getAll: () => event.cookies.getAll(),
27-
setAll: (cookiesToSet) => {
28-
cookiesToSet.forEach(({ name, value, options }) => {
29-
event.cookies.set(name, value, { ...options, path: "/" })
30-
})
31-
}
32-
},
33-
global: {
34-
fetch: (input: string | URL | Request, init?: RequestInit) => {
35-
console.log("Server hook: ", input)
36-
return event.fetch(input, init)
24+
event.locals.supabaseServer = createServerClient<Database>(
25+
PUBLIC_LOCAL_SUPABASE_URL,
26+
PUBLIC_SUPABASE_ANON_KEY,
27+
{
28+
cookies: {
29+
getAll: () => event.cookies.getAll(),
30+
setAll: (cookiesToSet) => {
31+
cookiesToSet.forEach(({ name, value, options }) => {
32+
event.cookies.set(name, value, { ...options, path: "/" })
33+
})
34+
}
35+
},
36+
global: {
37+
fetch: (input: string | URL | Request, init?: RequestInit) => {
38+
console.log("Server hook: ", input)
39+
40+
return event.fetch(input, init)
41+
}
3742
}
3843
}
39-
})
44+
)
4045

4146
event.locals.safeGetSession = async () => {
4247
const start = performance.now()

src/lib/server/supabase.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { SUPABASE_SERVICE_KEY } from "$env/static/private"
2-
import { PUBLIC_SUPABASE_URL } from "$env/static/public"
2+
import { PUBLIC_LOCAL_SUPABASE_URL } from "$env/static/public"
33
import type { Database } from "$lib/types/supabase"
44
import { formatError } from "$lib/utils"
55
import { type SupabaseClient, createClient, type Provider } from "@supabase/supabase-js"
66
import { error, redirect } from "@sveltejs/kit"
77

8-
export const supabaseAdmin = createClient<Database>(PUBLIC_SUPABASE_URL, SUPABASE_SERVICE_KEY, {
8+
export const supabaseAdmin = createClient<Database>(PUBLIC_LOCAL_SUPABASE_URL, SUPABASE_SERVICE_KEY, {
99
auth: { autoRefreshToken: true, persistSession: false }
1010
})
1111

src/routes/+layout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createBrowserClient, createServerClient, isBrowser } from "@supabase/ssr"
2-
import { PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY } from "$env/static/public"
2+
import { PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, PUBLIC_LOCAL_SUPABASE_URL } from "$env/static/public"
33
import type { Session, User } from "@supabase/supabase-js"
44

55
export const load = async ({ data, depends, fetch }) => {
@@ -15,7 +15,7 @@ export const load = async ({ data, depends, fetch }) => {
1515
}
1616
}
1717
})
18-
: createServerClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
18+
: createServerClient(PUBLIC_LOCAL_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
1919
global: {
2020
fetch: (input: string | URL | Request, init?: RequestInit) => {
2121
console.log("Layout Server: ", input)

0 commit comments

Comments
 (0)