From 7089515e47fb6f7e9aa3db4bbbac2d3300ff0048 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 11 Aug 2024 15:32:47 +0900 Subject: feat(frontend): improve error handling of login form --- frontend/app/.server/auth.ts | 5 +- frontend/app/components/BorderedContainer.tsx | 13 +++ frontend/app/components/InputText.tsx | 12 +++ frontend/app/components/SubmitButton.tsx | 12 +++ frontend/app/routes/_index.tsx | 25 +++-- frontend/app/routes/login.tsx | 150 +++++++++++++++++--------- 6 files changed, 155 insertions(+), 62 deletions(-) create mode 100644 frontend/app/components/BorderedContainer.tsx create mode 100644 frontend/app/components/InputText.tsx create mode 100644 frontend/app/components/SubmitButton.tsx (limited to 'frontend/app') diff --git a/frontend/app/.server/auth.ts b/frontend/app/.server/auth.ts index 943f424..4df0924 100644 --- a/frontend/app/.server/auth.ts +++ b/frontend/app/.server/auth.ts @@ -32,9 +32,12 @@ export type User = components["schemas"]["User"]; // Remix's createCookie() returns "structured" cookies, which cannot be reused directly by non-Remix servers. const tokenCookie = createUnstructuredCookie("albatross_token", cookieOptions); +/** + * @throws Error on failure + */ export async function login(request: Request): Promise { const jwt = await authenticator.authenticate("default", request, { - failureRedirect: request.url, + throwOnError: true, }); const session = await sessionStorage.getSession( diff --git a/frontend/app/components/BorderedContainer.tsx b/frontend/app/components/BorderedContainer.tsx new file mode 100644 index 0000000..cbbfbde --- /dev/null +++ b/frontend/app/components/BorderedContainer.tsx @@ -0,0 +1,13 @@ +import React from "react"; + +type Props = { + children: React.ReactNode; +}; + +export default function BorderedContainer({ children }: Props) { + return ( +
+ {children} +
+ ); +} diff --git a/frontend/app/components/InputText.tsx b/frontend/app/components/InputText.tsx new file mode 100644 index 0000000..3f2c526 --- /dev/null +++ b/frontend/app/components/InputText.tsx @@ -0,0 +1,12 @@ +import React from "react"; + +type InputProps = React.InputHTMLAttributes; + +export default function InputText(props: InputProps) { + return ( + + ); +} diff --git a/frontend/app/components/SubmitButton.tsx b/frontend/app/components/SubmitButton.tsx new file mode 100644 index 0000000..1400a7b --- /dev/null +++ b/frontend/app/components/SubmitButton.tsx @@ -0,0 +1,12 @@ +import React from "react"; + +type ButtonProps = React.ButtonHTMLAttributes; + +export default function SubmitButton(props: ButtonProps) { + return ( + - +
+ +
+

+ fortee アカウントでログイン +

+

+ fortee + のアカウントをお持ちでない場合は、イベントスタッフにお声がけください。 +

+ {loginErrors?.message && ( +

{loginErrors.message}

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

+ {loginErrors.errors.username} +

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

+ {loginErrors.errors.password} +

+ )} +
+ +
+ ログイン +
+
+
+
); } -- cgit v1.2.3-70-g09d2