-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathusers.ts
More file actions
75 lines (70 loc) · 1.99 KB
/
users.ts
File metadata and controls
75 lines (70 loc) · 1.99 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import type { OkoApiResponse } from "@oko-wallet/oko-types/api_response";
import type {
ChangePasswordResponse,
LoginResponse,
SendVerificationResponse,
} from "@oko-wallet/oko-types/ct_dashboard";
import { errorHandle } from "./utils";
import { CUSTOMER_V1_ENDPOINT } from "./customers";
export async function requestSignIn(
email: string,
password: string,
): Promise<OkoApiResponse<LoginResponse>> {
return errorHandle<LoginResponse>(() =>
fetch(`${CUSTOMER_V1_ENDPOINT}/customer/auth/signin`, {
method: "POST",
body: JSON.stringify({ email, password }),
headers: {
"Content-Type": "application/json",
},
}),
);
}
export async function requestSendVerificationCode(
email: string,
): Promise<OkoApiResponse<SendVerificationResponse>> {
return errorHandle<SendVerificationResponse>(() =>
fetch(`${CUSTOMER_V1_ENDPOINT}/customer/auth/send-code`, {
method: "POST",
body: JSON.stringify({ email }),
headers: {
"Content-Type": "application/json",
},
}),
);
}
export async function requestVerifyCodeAndLogin(
email: string,
code: string,
): Promise<OkoApiResponse<LoginResponse>> {
return errorHandle<LoginResponse>(() =>
fetch(`${CUSTOMER_V1_ENDPOINT}/customer/auth/verify-login`, {
method: "POST",
body: JSON.stringify({ email, verification_code: code }),
headers: {
"Content-Type": "application/json",
},
}),
);
}
export async function requestChangePassword(
email: string,
originalPassword: string,
newPassword: string,
token: string,
): Promise<OkoApiResponse<ChangePasswordResponse>> {
return errorHandle<any>(() =>
fetch(`${CUSTOMER_V1_ENDPOINT}/customer/auth/change-password`, {
method: "POST",
body: JSON.stringify({
email,
original_password: originalPassword,
new_password: newPassword,
}),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
}),
);
}