-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Ojas-Arora:main' into main
- Loading branch information
Showing
8 changed files
with
363 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
import mongoose from 'mongoose'; | ||
import dotenv from 'dotenv' | ||
|
||
dotenv.config() | ||
// Database connection | ||
export const dbConnect = async () => { | ||
const url = process.env.MONGO_URI; | ||
|
||
if (!url) { | ||
console.error('No URL received from env. Check .env file path.'); | ||
process.exit(1); | ||
} | ||
|
||
const dbConnect = async () => { | ||
try { | ||
await mongoose.connect(url); | ||
console.log('MongoDB connected'); | ||
} catch (err) { | ||
console.error('Database connection error:', err); | ||
process.exit(1); // Exit process with failure | ||
await mongoose.connect('mongodb://127.0.0.1:27017/scd_profile_db'); | ||
console.log("Database connected successfully!"); | ||
} catch (error) { | ||
console.error("Database connection error:", error); | ||
} | ||
}; | ||
|
||
export default dbConnect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const loginForm = document.getElementById('loginForm'); | ||
if (loginForm) { | ||
loginForm.addEventListener('submit', handleLoginSubmit); | ||
} | ||
}); | ||
|
||
function handleLoginSubmit(event) { | ||
event.preventDefault(); // Prevent the default form submission | ||
|
||
const email = document.getElementById('email').value; | ||
const password = document.getElementById('password').value; | ||
|
||
const formData = { email, password }; | ||
|
||
|
||
fetch('http://localhost:3000/api/v1/auth/login', { | ||
|
||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(formData), | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data.token) { | ||
alert('Login successful!'); | ||
localStorage.setItem('authToken', data.token); | ||
window.location.href = './index.html'; | ||
} else { | ||
alert('Login failed: ' + data.message); | ||
} | ||
}) | ||
.catch(error => console.error('Error:', error)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.