@supabase/auth-helpers-sveltekit
Advanced tools
Comparing version 0.8.3 to 0.8.4
export declare const PKG_NAME = "@supabase/auth-helpers-sveltekit"; | ||
export declare const PKG_VERSION = "0.8.3"; | ||
export declare const PKG_VERSION = "0.8.4"; |
export const PKG_NAME = '@supabase/auth-helpers-sveltekit'; | ||
export const PKG_VERSION = '0.8.3'; | ||
export const PKG_VERSION = '0.8.4'; |
@@ -12,2 +12,3 @@ import { getConfig } from '../config.js'; | ||
auth: { | ||
autoRefreshToken: false, | ||
storage: { | ||
@@ -14,0 +15,0 @@ async getItem(key) { |
{ | ||
"name": "@supabase/auth-helpers-sveltekit", | ||
"version": "0.8.3", | ||
"version": "0.8.4", | ||
"description": "A collection of framework specific Auth utilities for working with Supabase.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -219,5 +219,3 @@ # @supabase/auth-helpers-sveltekit (BETA) | ||
} | ||
const { data: tableData } = await supabaseClient | ||
.from('test') | ||
.select('*'); | ||
const { data: tableData } = await supabaseClient.from('test').select('*'); | ||
@@ -246,5 +244,3 @@ return { | ||
} | ||
const { data } = await supabaseClient | ||
.from('test') | ||
.select('*'); | ||
const { data } = await supabaseClient.from('test').select('*'); | ||
@@ -313,20 +309,23 @@ return json({ data }); | ||
const { error } = await supabaseClient.auth.signInWithPassword({ email, password }); | ||
const { error } = await supabaseClient.auth.signInWithPassword({ | ||
email, | ||
password | ||
}); | ||
if (error) { | ||
if (error instanceof AuthApiError && error.status === 400) { | ||
return invalid(400, { | ||
error: 'Invalid credentials.', | ||
values: { | ||
} | ||
}); | ||
} | ||
return invalid(500, { | ||
error: 'Server error. Try again later.', | ||
values: { | ||
} | ||
}); | ||
} | ||
if (error instanceof AuthApiError && error.status === 400) { | ||
return invalid(400, { | ||
error: 'Invalid credentials.', | ||
values: { | ||
} | ||
}); | ||
} | ||
return invalid(500, { | ||
error: 'Server error. Try again later.', | ||
values: { | ||
} | ||
}); | ||
} | ||
@@ -343,1 +342,38 @@ throw redirect(303, '/dashboard'); | ||
``` | ||
## Protecting multiple routes | ||
To avoid writing the same auth logic in every single route you can use the handle hook to | ||
protect multiple routes at once. | ||
```ts | ||
// src/hooks.server.ts | ||
import type { RequestHandler } from './$types'; | ||
import { getSupabase } from '@supabase/auth-helpers-sveltekit'; | ||
import { redirect, error } from '@sveltejs/kit'; | ||
export const handle: Handle = async ({ event, resolve }) => { | ||
// protect requests to all routes that start with /protected-routes | ||
if (event.url.pathname.startsWith('/protected-routes')) { | ||
const { session, supabaseClient } = await getSupabase(event); | ||
if (!session) { | ||
throw redirect(303, '/'); | ||
} | ||
} | ||
// protect POST requests to all routes that start with /protected-posts | ||
if ( | ||
event.url.pathname.startsWith('/protected-posts') && | ||
event.request.method === 'POST' | ||
) { | ||
const { session, supabaseClient } = await getSupabase(event); | ||
if (!session) { | ||
throw error(303, '/'); | ||
} | ||
} | ||
return resolve(event); | ||
}; | ||
``` |
21193
210
376