move better-auth demo to auth dir
This commit is contained in:
20
src/routes/auth/+page.server.ts
Normal file
20
src/routes/auth/+page.server.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { Actions } from './$types';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { auth } from '$lib/server/auth';
|
||||
|
||||
export const load: PageServerLoad = (event) => {
|
||||
if (!event.locals.user) {
|
||||
return redirect(302, '/auth/login');
|
||||
}
|
||||
return { user: event.locals.user };
|
||||
};
|
||||
|
||||
export const actions: Actions = {
|
||||
signOut: async (event) => {
|
||||
await auth.api.signOut({
|
||||
headers: event.request.headers
|
||||
});
|
||||
return redirect(302, '/auth/login');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user