-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArchitectureArchiveFE
51 lines (46 loc) · 1.12 KB
/
ArchitectureArchiveFE
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
import firebase from 'firebase/app';
import 'firebase/auth';
import { clientCredentials } from './utils/client';
const checkUser = (uid) => new Promise((resolve, reject) => {
fetch(`${clientCredentials.databaseURL}/checkuser`, {
method: 'POST',
body: JSON.stringify({ uid }),
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
})
.then((resp) => {
if (resp.ok) {
resolve(resp.json());
} else {
resolve({});
}
})
.catch(reject);
});
const registerUser = (userInfo) => new Promise((resolve, reject) => {
fetch(`${clientCredentials.databaseURL}/api/register`, {
method: 'POST',
body: JSON.stringify(userInfo),
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
})
.then((resp) => resolve(resp.json()))
.catch(reject);
});
const signIn = () => {
const provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider);
};
const signOut = () => {
firebase.auth().signOut();
};
export {
signIn, //
signOut,
checkUser,
registerUser,
};