-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
66 lines (56 loc) · 2.14 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
60
61
62
63
64
65
66
const express = require("express")
const dotenv = require("dotenv")
const bodyparser = require("body-parser")
const path = require('path')
const { initializeApp } = require("firebase/app")
const { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword } = require("firebase/auth")
const { log } = require("console")
const app = express();
dotenv.config();
app.use(express.static(path.join(__dirname, 'views')));
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyparser.urlencoded({ extended: true }))
app.use(bodyparser.json())
const firebaseConfig = {
apiKey: process.env.FIREBASE_API,
authDomain: process.env.AUTHDOMAIN,
projectId: process.env.PROJECTID,
storageBucket: "krishi-connect12.appspot.com",
messagingSenderId: "44448474566",
appId: "1:44448474566:web:93807fd8396b0157bebec7",
measurementId: "G-J138W8N9ZF"
};
const firebaseApp = initializeApp(firebaseConfig);
const auth = getAuth(firebaseApp);
app.get("/", function (req, res) {
res.sendFile(path.join(__dirname, "views", "landingPage.html"));
});
app.post('/signup', function (req, res) {
const name = req.body.name;
const email = req.body.email;
const password = req.body.password;
console.log(name, email, password);
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
res.status(200).send("User created successfully: " + userCredential.user.uid);
})
.catch((error) => {
console.error("Error creating user:", error);
res.status(400).send("Error: " + error.message);
});
});
app.post("/signin", function (req, res) {
const email = req.body.email;
const password = req.body.password;
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
res.status(200).send("User signed in successfully: " + userCredential.user.uid);
})
.catch((error) => {
console.error("Error signing in:", error);
res.status(400).send("Error: " + error.message);
});
})
app.listen(process.env.PORT, function(req,res){
console.log(process.env.PORT);
})