From 28f781e48c8442ecd0321cf83108bcbe0bd8f860 Mon Sep 17 00:00:00 2001 From: rajun Date: Tue, 27 Oct 2026 16:28:59 +0530 Subject: [PATCH] feat: add redesigned login page --- app/routes/login.tsx | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 app/routes/login.tsx diff --git a/app/routes/login.tsx b/app/routes/login.tsx new file mode 100644 index 0000000..740a001 --- /dev/null +++ b/app/routes/login.tsx @@ -0,0 +1,45 @@ +import { redirect, useActionData } from 'react-router'; +import { ClientResponseError } from 'pocketbase'; +import type { Route } from './+types/login'; +import { LoginPanel } from '~/components/auth/form/login-panel'; +import { LoginShowcase } from '~/components/auth/showcase/login-showcase'; +import { LoadingScreen } from '~/components/ui/loading-screen'; +import { LOGIN_ERRORS } from '~/data/auth/constants'; +import { ROUTES } from '~/data/routes'; +import { getErrorMessage } from '~/lib/errors'; +import { loginSchema } from '~/schemas/auth/login'; +import { isSignedIn, signIn } from '~/services/auth'; +import type { LoginFailure } from '~/types/auth'; + +export async function clientLoader() { + return isSignedIn() ? redirect(ROUTES.home) : null; +} + +export async function clientAction({ request }: Route.ClientActionArgs) { + const parsed = loginSchema.safeParse(await request.json()); + if (!parsed.success) return { error: parsed.error.issues[0]?.message ?? LOGIN_ERRORS.mismatch, invalidCredentials: false } satisfies LoginFailure; + + const { email, password, remember } = parsed.data; + try { + await signIn(email, password, remember); + } catch (error) { + const status = error instanceof ClientResponseError ? error.status : undefined; + if (status === 400) return { error: LOGIN_ERRORS.mismatch, invalidCredentials: true } satisfies LoginFailure; + return { error: status === 0 ? LOGIN_ERRORS.offline : getErrorMessage(error), invalidCredentials: false } satisfies LoginFailure; + } + return redirect(ROUTES.home); +} + +export function HydrateFallback() { + return ; +} + +export default function Login() { + const failure = useActionData(); + return ( +
+ + +
+ ); +}