File size: 550 Bytes
e8de0f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// frontend/src/api.ts
export const api = {
  login,
  getUser,
};

export async function login(email: string, password: string) {
  const res = await fetch("/api/login", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    credentials: "include", // important to send session cookie
    body: JSON.stringify({ email, password })
  });
  return res.json();
}

export async function getUser() {
  const res = await fetch("/api/user", {
    method: "GET",
    credentials: "include" // important!
  });
  return res.json();
}