diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-09 23:30:39 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-09 23:30:39 +0900 |
| commit | 41e98f3b0a936f7982434b74a88b919b99fd94ce (patch) | |
| tree | 72e1a3cc00044f9c00dc5f22ef9325124f272401 /frontend | |
| parent | 93f2ffc18d1d86bd2999533e8d904c92cb29bc1a (diff) | |
| parent | af36c59851399194bcbb77a3093d46c2757cb7b4 (diff) | |
| download | phperkaigi-2025-albatross-41e98f3b0a936f7982434b74a88b919b99fd94ce.tar.gz phperkaigi-2025-albatross-41e98f3b0a936f7982434b74a88b919b99fd94ce.tar.zst phperkaigi-2025-albatross-41e98f3b0a936f7982434b74a88b919b99fd94ce.zip | |
Merge branch 'feat/auth-fortee'
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/app/.server/api/client.ts | 14 | ||||
| -rw-r--r-- | frontend/app/.server/api/schema.d.ts | 2 | ||||
| -rw-r--r-- | frontend/app/.server/auth.ts | 11 | ||||
| -rw-r--r-- | frontend/app/routes/login.tsx | 11 |
4 files changed, 33 insertions, 5 deletions
diff --git a/frontend/app/.server/api/client.ts b/frontend/app/.server/api/client.ts index 0db4c14..aae1723 100644 --- a/frontend/app/.server/api/client.ts +++ b/frontend/app/.server/api/client.ts @@ -8,9 +8,19 @@ const apiClient = createClient<paths>({ : "http://api-server/api/", }); -export async function apiPostLogin(username: string, password: string) { +export async function apiPostLogin( + username: string, + password: string, + registrationToken: string | null, +) { const { data, error } = await apiClient.POST("/login", { - body: { username, password }, + body: { + username, + password, + ...(registrationToken !== null + ? { registration_token: registrationToken } + : {}), + }, }); if (error) throw new Error(error.message); return data; diff --git a/frontend/app/.server/api/schema.d.ts b/frontend/app/.server/api/schema.d.ts index 6981dea..9a96f19 100644 --- a/frontend/app/.server/api/schema.d.ts +++ b/frontend/app/.server/api/schema.d.ts @@ -286,6 +286,8 @@ export interface operations { username: string; /** @example password123 */ password: string; + /** @example xxxxxxxxxxxxxxxx */ + registration_token?: string; }; }; }; diff --git a/frontend/app/.server/auth.ts b/frontend/app/.server/auth.ts index 2c9d23c..943f424 100644 --- a/frontend/app/.server/auth.ts +++ b/frontend/app/.server/auth.ts @@ -14,7 +14,14 @@ authenticator.use( new FormStrategy(async ({ form }) => { const username = String(form.get("username")); const password = String(form.get("password")); - return (await apiPostLogin(username, password)).token; + const registrationToken = String(form.get("registration_token")); + return ( + await apiPostLogin( + username, + password, + registrationToken === "" ? null : registrationToken, + ) + ).token; }), "default", ); @@ -27,7 +34,7 @@ const tokenCookie = createUnstructuredCookie("albatross_token", cookieOptions); export async function login(request: Request): Promise<never> { const jwt = await authenticator.authenticate("default", request, { - failureRedirect: "/login", + failureRedirect: request.url, }); const session = await sessionStorage.getSession( diff --git a/frontend/app/routes/login.tsx b/frontend/app/routes/login.tsx index dc87d47..d6414f7 100644 --- a/frontend/app/routes/login.tsx +++ b/frontend/app/routes/login.tsx @@ -3,7 +3,7 @@ import type { LoaderFunctionArgs, MetaFunction, } from "@remix-run/node"; -import { Form } from "@remix-run/react"; +import { Form, useLocation } from "@remix-run/react"; import { ensureUserNotLoggedIn, login } from "../.server/auth"; export const meta: MetaFunction = () => [ @@ -20,6 +20,10 @@ export async function action({ request }: ActionFunctionArgs) { } export default function Login() { + const location = useLocation(); + const searchParams = new URLSearchParams(location.search); + const registrationToken = searchParams.get("registration_token"); + return ( <div className="min-h-screen bg-gray-100 flex items-center justify-center"> <Form @@ -58,6 +62,11 @@ export default function Login() { className="mt-1 p-2 block w-full border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500" /> </div> + <input + type="hidden" + name="registration_token" + value={registrationToken ?? ""} + /> <button type="submit" className="w-full bg-blue-500 text-white py-2 rounded hover:bg-blue-600 transition duration-300" |
