-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.tsx
48 lines (44 loc) · 1.34 KB
/
register.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// app/routes/register.tsx
import { type ActionFunction, json } from '@remix-run/node'
import { registerUser } from '~/auth/authenticator.server'
// import { commitSession, getSession } from '~/components/pending/flash-session.server'
/**
* Handles the registration action.
*
* @param request - The request object.
* @returns The response object.
*/
export const action: ActionFunction = async ({ request }) => {
// const session = await getSession(
// request.headers.get("Cookie")
// );
const formData = await request.formData()
const email = formData.get('email') as string
const password = formData.get('password') as string
// const data = { error: session.get("error") };
try {
const result = await registerUser(email, password)
if (result.status === 'success' && result.statusCode === 200) {
// If login is successful indicate success somehow.
return json({
success: 'Registration successful',
})
} else {
// Return error message from API
return json(
{
error: result.message,
},
{
status: result.statusCode,
// headers: {
// "Set-Cookie": await commitSession(session),
// } as HeadersInit, // Cast headers object to HeadersInit type
},
)
}
} catch (error) {
const message = (error as Error).message || 'Unable to register'
return json({ message }, { status: 500 })
}
}