-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.server.ts
48 lines (41 loc) · 1.21 KB
/
user.server.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
38
39
40
41
42
43
44
45
46
47
48
import { API_BASE_URL } from '~/constants.server';
import type { Note } from './note.server';
export type User = {
id: string;
email: string;
createdAt: Date;
updatedAt: Date;
notes: Note[];
};
export async function getUserById(id: User['id']) {
const response = await fetch(`${API_BASE_URL}/users/${id}`);
return response.json();
}
export async function getUserByEmail(email: User['email']) {
const response = await fetch(`${API_BASE_URL}/users?email=${email}`);
if (response.ok) {
return response.json();
}
return null;
}
export async function createUser(email: User['email'], password: string) {
const response = await fetch(`${API_BASE_URL}/users`, {
method: 'POST',
body: JSON.stringify({ email, password }),
});
return response.json();
}
export async function deleteUserByEmail(email: User['email']) {
const response = await fetch(`${API_BASE_URL}/users`, {
method: 'DELETE',
body: JSON.stringify({ email }),
});
return response.ok;
}
export async function verifyLogin(email: User['email'], password: string) {
const response = await fetch(`${API_BASE_URL}/login`, {
method: 'POST',
body: JSON.stringify({ email, password }),
});
return response.json();
}