diff --git a/src/routes/(auth)/auth/(components)/index.ts b/src/routes/(auth)/auth/(components)/index.ts
index 14e9bda..f70a7d6 100644
--- a/src/routes/(auth)/auth/(components)/index.ts
+++ b/src/routes/(auth)/auth/(components)/index.ts
@@ -1,3 +1,3 @@
export { default as LoginForm } from './login-form.svelte';
export { default as RegisterForm } from './register-form.svelte';
-export { default as SSOForm } from './sso-form.svelte';
+export { default as Oauth2Form } from './oauth2-form.svelte';
diff --git a/src/routes/(auth)/auth/(components)/login-form.svelte b/src/routes/(auth)/auth/(components)/login-form.svelte
index b244264..5a83527 100644
--- a/src/routes/(auth)/auth/(components)/login-form.svelte
+++ b/src/routes/(auth)/auth/(components)/login-form.svelte
@@ -14,7 +14,6 @@
import SuperDebug from 'sveltekit-superforms';
import { zodClient } from 'sveltekit-superforms/adapters';
import { browser, dev } from '$app/environment';
- // import { PUBLIC_DEBUG_FORMS } from '$env/static/public';
import { toast } from 'svelte-sonner';
import { Icons } from '$lib/components/site';
import { cn } from '$lib/utils';
@@ -31,12 +30,22 @@
},
onUpdated: ({ form: f }) => {
isLoading = false;
- if (f.valid) {
- toast.success('Succesfully logged in.');
- } else {
+ if (!f.valid) {
toast.error('Please fix the errors.');
}
+ },
+ onError: (e) => {
+ toast.error(e.result.error.message);
+ },
+ onResult: (e) => {
+ if (e.result.status === 303) {
+ toast.success('Logged in successfully.');
+ } else {
+ console.log(e)
+ toast.error('Invalid credentials.');
+ }
}
+
});
const { form: formData, enhance } = form;
diff --git a/src/routes/(auth)/auth/(components)/sso-form.svelte b/src/routes/(auth)/auth/(components)/oauth2-form.svelte
similarity index 69%
rename from src/routes/(auth)/auth/(components)/sso-form.svelte
rename to src/routes/(auth)/auth/(components)/oauth2-form.svelte
index 14962dd..293b942 100644
--- a/src/routes/(auth)/auth/(components)/sso-form.svelte
+++ b/src/routes/(auth)/auth/(components)/oauth2-form.svelte
@@ -1,49 +1,14 @@
-
-
-
-
-
-
-
-
-
+
-
-{#if dev && debugForms && browser}
-
-
-
-{/if}
diff --git a/src/routes/(auth)/auth/+page.server.ts b/src/routes/(auth)/auth/+page.server.ts
index 15f6c76..9e39e50 100644
--- a/src/routes/(auth)/auth/+page.server.ts
+++ b/src/routes/(auth)/auth/+page.server.ts
@@ -3,14 +3,12 @@ import { superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { loginFormSchema } from './(components)/login-form.svelte';
import { registerFormSchema } from './(components)/register-form.svelte';
-import { ssoFormSchema } from './(components)/sso-form.svelte';
import { fail, type Actions, redirect } from '@sveltejs/kit';
export const load: PageServerLoad = async () => {
return {
loginForm: await superValidate(zod(loginFormSchema)),
- registerForm: await superValidate(zod(registerFormSchema)),
- ssoForm: await superValidate(zod(ssoFormSchema))
+ registerForm: await superValidate(zod(registerFormSchema))
};
};
@@ -54,26 +52,13 @@ export const actions: Actions = {
});
}
},
- sso: async ({ request, cookies }) => {
- const form = await superValidate(request, zod(ssoFormSchema));
- if (!form.valid) {
- return fail(400, {
- form
- });
- }
- const token = form.data.token;
- try {
- if (!token || typeof token !== 'string') {
- throw redirect(303, '/auth');
- }
- cookies.set('pb_auth', JSON.stringify({ token: token }), { path: '/' });
- return {
- form
- };
- } catch (err) {
- return fail(500, {
- form
- });
+ oauth2: async ({ request, cookies }) => {
+ const form = await request.formData();
+ const token = form.get('token');
+ if (!token || typeof token !== 'string') {
+ throw redirect(303, '/auth');
}
+ cookies.set('pb_auth', JSON.stringify({ token: token }), { path: '/' });
+ throw redirect(303, '/');
}
};
diff --git a/src/routes/(auth)/auth/+page.svelte b/src/routes/(auth)/auth/+page.svelte
index 19c21ef..71d0fd1 100644
--- a/src/routes/(auth)/auth/+page.svelte
+++ b/src/routes/(auth)/auth/+page.svelte
@@ -3,7 +3,7 @@
import { Icons } from '$lib/components/site/index.js';
import * as Tabs from '$lib/components/ui/tabs';
import type { PageData } from './$types.js';
- import { LoginForm, RegisterForm, SSOForm } from './(components)';
+ import { LoginForm, RegisterForm, Oauth2Form } from './(components)';
export let data: PageData;
@@ -37,7 +37,7 @@
Forgot password? Reset password.
{#if providers.length}
-
+
{/if}