diff --git a/src/routes/auth/login/+page.server.ts b/src/routes/auth/login/+page.server.ts new file mode 100644 index 00000000..f6af4df7 --- /dev/null +++ b/src/routes/auth/login/+page.server.ts @@ -0,0 +1,34 @@ +import type { Actions, PageServerLoad } from './$types' +import { fail, redirect } from '@sveltejs/kit' + +export const load: PageServerLoad = async ({ locals, url }) => { + if (locals.session.isAuthenticated) { + redirect(302, url.searchParams.get('next') ?? '/me') + } + return {} +} + +export const actions: Actions = { + default: async ({ request, fetch, url }) => { + const form = await request.formData() + const email = String(form.get('email') ?? '') + const password = String(form.get('password') ?? '') + + if (!email || !password) { + return fail(400, { error: 'Email and password are required', email }) + } + + const res = await fetch('/auth/login', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ email, password, grant_type: 'password' }) + }) + + if (res.ok) { + redirect(303, url.searchParams.get('next') ?? '/me') + } + + const j = await res.json().catch(() => ({})) + return fail(res.status, { error: j.error ?? 'Login failed', email }) + } +} diff --git a/src/routes/auth/login/+page.svelte b/src/routes/auth/login/+page.svelte new file mode 100644 index 00000000..c1a51029 --- /dev/null +++ b/src/routes/auth/login/+page.svelte @@ -0,0 +1,94 @@ + + + + {m.auth_login_title()} | Granblue Party + + + +
{ + isSubmitting = true + return async ({ update }) => { + isSubmitting = false + await update() + } + }} + > + + + + + {#if form?.error} +

{form.error}

+ {/if} + + +
+ + {#snippet footer()} +

+ {m.auth_login_noAccount()} + {m.auth_login_register()} +

+ {/snippet} +
+ +