Skip to content

Commit

Permalink
IC
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWick7796 committed Dec 19, 2020
0 parents commit 72b1d92
Show file tree
Hide file tree
Showing 4 changed files with 1,948 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
59 changes: 59 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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}!`);
});
Loading

0 comments on commit 72b1d92

Please sign in to comment.