import type { ActionFunctionArgs, LoaderFunctionArgs, MetaFunction, } from "react-router"; import { Form, data, useActionData } from "react-router"; import { ensureUserNotLoggedIn, login } from "../.server/auth"; import BorderedContainer from "../components/BorderedContainer"; import InputText from "../components/InputText"; import SubmitButton from "../components/SubmitButton"; export const meta: MetaFunction = () => [ { title: "Login | PHPerKaigi 2025 Albatross" }, ]; export async function loader({ request }: LoaderFunctionArgs) { return await ensureUserNotLoggedIn(request); } export async function action({ request }: ActionFunctionArgs) { const formData = await request.clone().formData(); const username = String(formData.get("username")); const password = String(formData.get("password")); if (username === "" || password === "") { return data( { message: "ユーザー名またはパスワードが誤っています", errors: { username: username === "" ? "ユーザー名を入力してください" : undefined, password: password === "" ? "パスワードを入力してください" : undefined, }, }, { status: 400 }, ); } try { await login(request); } catch (error) { if (error instanceof Error) { return data( { message: error.message, errors: { username: undefined, password: undefined, }, }, { status: 400 }, ); } else { throw error; } } return null; } export default function Login() { const loginErrors = useActionData(); return (

fortee アカウントでログイン

{loginErrors?.message && (

{loginErrors.message}

)}
{loginErrors?.errors?.username && (

{loginErrors.errors.username}

)}
{loginErrors?.errors?.password && (

{loginErrors.errors.password}

)}
ログイン
); }