-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (56 loc) · 1.44 KB
/
index.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
const express = require("express");
const app = express();
const port = 3000;
const firebase = require("firebase/app");
require("firebase/auth");
require("firebase/firestore");
const firebaseConfig = {
apiKey: "AIzaSyBAwmNk8Ch2KWM0havXYLvpFwJSlxGSVNA",
authDomain: "hanasu-2.firebaseapp.com",
projectId: "hanasu-2",
storageBucket: "hanasu-2.appspot.com",
messagingSenderId: "245069176356",
appId: "1:245069176356:web:4e04f966f93730898a42b1"
};
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
app.use(express.json());
app.post("/signin", (req, res) => {
firebase
.auth()
.signInWithEmailAndPassword(req.body.email, req.body.password)
.then((result) => {
res.send({
uid: result.user.uid,
loggedIn: true
});
})
.catch((error) => {
console.error(error.message);
res.send(error.message);
});
});
app.post("/signup", (req, res) => {
firebase
.auth()
.createUserWithEmailAndPassword(req.body.email, req.body.password)
.then((result) => {
db.collection("Users").doc(result.user.uid).set({
email: req.body.email,
username: req.body.username,
target_language: req.body.target_language,
proficient_language: req.body.proficient_language
});
res.send({
uid: result.user.uid,
loggedIn: true
});
})
.catch((error) => {
console.error(error.message);
res.send(error.message);
});
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}!`);
});