-
Notifications
You must be signed in to change notification settings - Fork 5
/
actionPassword.ts
37 lines (34 loc) · 1.07 KB
/
actionPassword.ts
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
import { json } from "@remix-run/node"
import { ActionDataStruct } from "~/types/global"
import { getErrorMessage } from "~/utils/catchError"
import { getRequiredServerEnvVar } from "~/utils/environment"
export type ActionPassword = { auth0: number }
export const actionPassword = async (email: string) => {
try {
const res = await fetch(
`https://${getRequiredServerEnvVar("AUTH0_DOMAIN")}/dbconnections/change_password`,
{
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
client_id: getRequiredServerEnvVar("AUTH0_CLIENT_ID"),
email,
connection: getRequiredServerEnvVar("AUTH0_CONNECTION"),
}),
},
)
return json<ActionDataStruct<ActionPassword>>({
data: {
auth0: res.status,
},
error: false,
message: "We've just sent you an email to reset your password.",
})
} catch (error) {
return json<ActionDataStruct<ActionPassword>>({
data: null,
error: true,
message: getErrorMessage(error),
})
}
}