diff options
Diffstat (limited to 'frontend/app/.server')
| -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 |
3 files changed, 23 insertions, 4 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( |
