-
Notifications
You must be signed in to change notification settings - Fork 1
/
backend.js
61 lines (56 loc) · 1.3 KB
/
backend.js
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
const BASE_URL = "https://memory-game-x3fx.onrender.com/api/v1" //"http://127.0.0.1:8000/api/v1" for local env
const loggedInUserData = {}
function handleSignup() {
const userData = {
username: fullName.value,
email: email.value,
password: password.value
};
fetch(`${BASE_URL}/users`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(userData)
})
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('Signup failed');
}
})
.then(data => {
loggedInUserData = data
console.log('Signup successful:', data);
})
.catch(error => {
console.error('Signup error:', error);
});
}
function handleLogin() {
const credentials = {
email: Email.value,
password: LPassword.value
};
fetch(`${BASE_URL}/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(credentials)
})
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('Login failed');
}
})
.then(data => {
console.log('Login successful:', data);
})
.catch(error => {
console.error('Login error:', error);
});
}