-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DATABASE_URL=mysql://root:password@localhost:3002/orbital |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const mysql = require('mysql2'); | ||
|
||
// Creating a connection | ||
const planetscale = mysql.createConnection({ | ||
host: 'aws.connect.psdb.cloud', | ||
user: 'lh8dzd33eoy0mrlf5jx3', | ||
password: 'pscale_pw_zhDbFsY97GESqb678oAtusj0URcj1Ne621LNXaZTjSI', | ||
database: 'orbital', | ||
ssl: { rejectUnauthorized: true }, | ||
multipleStatements: true, | ||
}); | ||
|
||
// Connecting to the database | ||
planetscale.connect((err) => { | ||
if (err) { | ||
console.error('Error connecting to the database:', err); | ||
return; | ||
} | ||
|
||
console.log('Connected to the database!'); | ||
|
||
// Closing the connection | ||
// planetscale.end(); | ||
}); | ||
|
||
module.exports = planetscale; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const express = require('express'); | ||
const planetscale = require('./config/planetscale'); | ||
const cors = require('cors'); | ||
|
||
const app = express(); | ||
|
||
const PORT = 3002; | ||
app.use(cors()); | ||
app.use(express.json()); | ||
|
||
// Route for creating the user | ||
app.post('/api/signup', (req, res) => { | ||
const email = req.body.email; | ||
const username = req.body.username; | ||
const password = req.body.password; | ||
const query = "INSERT INTO users (email, username, password_hash) VALUES (?,?,?)"; | ||
|
||
planetscale.query(query, [email, username, password], (err, result) => { | ||
if (err) { | ||
return res.status(500).json({ error: 'Account already exists' }); | ||
} | ||
return res.status(200).json({ message: 'Signup successful' }); | ||
}); | ||
}); | ||
|
||
// Route for login | ||
app.post('/api/login', (req, res) => { | ||
const email = req.body.email; | ||
const password = req.body.password; | ||
const query = `SELECT * FROM users WHERE email = ?`; | ||
|
||
planetscale.query(query, email, (err, result) => { | ||
if (!data || data.length === 0) { | ||
return res.status(404).json({ error: 'Invalid email or password' }); | ||
} else if (result[0].password_hash !== password) { | ||
return res.status(401).json({ error: 'Invalid email or password' }); | ||
} | ||
return res.status(200).json({ message: 'Login successful' }); | ||
}); | ||
}); | ||
|
||
// Route for deleting account | ||
app.post('/api/delete-account', (req, res) => { | ||
const email = req.body.email; | ||
const query = `DELETE FROM users WHERE email = ?`; | ||
|
||
planetscale.query(query, email, (err, result) => { | ||
if (err) { | ||
return res.status(500).json({ error: 'An error occurred while deleting the account' }); | ||
} | ||
return res.status(200).json({ message: 'Account deleted successfully' }); | ||
}); | ||
}); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Server is running on ${PORT}`); | ||
}); |
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.