mirror of
https://github.com/jcreek/SvelteKitSaasBoilerplate.git
synced 2026-07-13 02:53:50 +00:00
refactor(#29): Add strong typing to locals supabase
This commit is contained in:
+18
-13
@@ -1,23 +1,28 @@
|
|||||||
import { PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY } from '$env/static/public';
|
import { PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY } from '$env/static/public';
|
||||||
import { createServerClient } from '@supabase/ssr';
|
import { createServerClient } from '@supabase/ssr';
|
||||||
import type { Handle } from '@sveltejs/kit';
|
import type { Handle } from '@sveltejs/kit';
|
||||||
|
import type { Database } from '$lib/generated/supabase-schema';
|
||||||
|
|
||||||
export const handle: Handle = async ({ event, resolve }) => {
|
export const handle: Handle = async ({ event, resolve }) => {
|
||||||
event.locals.supabase = createServerClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
|
event.locals.supabase = createServerClient<Database>(
|
||||||
cookies: {
|
PUBLIC_SUPABASE_URL,
|
||||||
getAll: () => event.cookies.getAll(),
|
PUBLIC_SUPABASE_ANON_KEY,
|
||||||
/**
|
{
|
||||||
* SvelteKit's cookies API requires `path` to be explicitly set in
|
cookies: {
|
||||||
* the cookie options. Setting `path` to `/` replicates previous/
|
getAll: () => event.cookies.getAll(),
|
||||||
* standard behavior.
|
/**
|
||||||
*/
|
* SvelteKit's cookies API requires `path` to be explicitly set in
|
||||||
setAll: (cookiesToSet) => {
|
* the cookie options. Setting `path` to `/` replicates previous/
|
||||||
cookiesToSet.forEach(({ name, value, options }) => {
|
* standard behavior.
|
||||||
event.cookies.set(name, value, { ...options, path: '/' });
|
*/
|
||||||
});
|
setAll: (cookiesToSet) => {
|
||||||
|
cookiesToSet.forEach(({ name, value, options }) => {
|
||||||
|
event.cookies.set(name, value, { ...options, path: '/' });
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlike `supabase.auth.getSession()`, which returns the session _without_
|
* Unlike `supabase.auth.getSession()`, which returns the session _without_
|
||||||
|
|||||||
Reference in New Issue
Block a user