This commit is contained in:
@@ -5,7 +5,7 @@ import { auth } from '$lib/server/auth';
|
||||
|
||||
export const load: PageServerLoad = (event) => {
|
||||
if (!event.locals.user) {
|
||||
return redirect(302, '/auth/login');
|
||||
throw redirect(302, '/auth/login');
|
||||
}
|
||||
return { user: event.locals.user };
|
||||
};
|
||||
@@ -15,6 +15,6 @@ export const actions: Actions = {
|
||||
await auth.api.signOut({
|
||||
headers: event.request.headers
|
||||
});
|
||||
return redirect(302, '/auth/login');
|
||||
throw redirect(302, '/auth/login');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import { APIError } from 'better-auth/api';
|
||||
|
||||
export const load: PageServerLoad = (event) => {
|
||||
if (event.locals.user) {
|
||||
return redirect(302, '/demo/auth');
|
||||
throw redirect(302, '/');
|
||||
}
|
||||
return {};
|
||||
};
|
||||
@@ -32,7 +32,7 @@ export const actions: Actions = {
|
||||
return fail(500, { message: 'Unexpected error' });
|
||||
}
|
||||
|
||||
return redirect(302, '/demo/auth');
|
||||
throw redirect(302, '/');
|
||||
},
|
||||
signUpEmail: async (event) => {
|
||||
const formData = await event.request.formData();
|
||||
@@ -56,12 +56,12 @@ export const actions: Actions = {
|
||||
return fail(500, { message: 'Unexpected error' });
|
||||
}
|
||||
|
||||
return redirect(302, '/demo/auth');
|
||||
throw redirect(302, '/');
|
||||
},
|
||||
signInSocial: async (event) => {
|
||||
const formData = await event.request.formData();
|
||||
const provider = formData.get('provider')?.toString() ?? 'github';
|
||||
const callbackURL = formData.get('callbackURL')?.toString() ?? '/demo/auth';
|
||||
const callbackURL = formData.get('callbackURL')?.toString() ?? '/';
|
||||
|
||||
const result = await auth.api.signInSocial({
|
||||
body: {
|
||||
@@ -71,7 +71,7 @@ export const actions: Actions = {
|
||||
});
|
||||
|
||||
if (result.url) {
|
||||
return redirect(302, result.url);
|
||||
throw redirect(302, result.url);
|
||||
}
|
||||
return fail(400, { message: 'Social sign-in failed' });
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
<form method="post" action="?/signInSocial" use:enhance>
|
||||
<input type="hidden" name="provider" value="github" />
|
||||
<input type="hidden" name="callbackURL" value="/demo/better-auth" />
|
||||
<input type="hidden" name="callbackURL" value="/" />
|
||||
<button class="rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700"
|
||||
>Sign in with GitHub</button
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user