-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
616 additions
and
135 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
NODE_ENV=development | ||
PORT=3000 | ||
MONGO_PATH="mongodb+srv://user:dbUserPassword@snappercluster.i3fur.mongodb.net/?retryWrites=true&w=majority&appName=SnapperCluster" | ||
MONGO_USERNAME="user" | ||
MONGO_PASSWORD="dbUserPassword" | ||
SUPABASE_PASSWORD="9waZ2NQKum6FmP$" | ||
SUPABASE_URL="https://xcgzrcnpyoxwxbjwnfnn.supabase.co" | ||
SUPABASE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhjZ3pyY25weW94d3hianduZm5uIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjU1NTMxOTUsImV4cCI6MjA0MTEyOTE5NX0.NgMdOTtSCbMdxkrzCgNYCyKBSLpzPuyARB8qnn3NKNo" |
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 |
---|---|---|
|
@@ -45,4 +45,7 @@ coverage/ | |
coverage-final.json | ||
|
||
#Build output | ||
build/ | ||
build/ | ||
|
||
# MongoDB data directory | ||
/data/ |
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,5 +1,9 @@ | ||
NODE_ENV=development | ||
PORT=3000 | ||
MONGO_PATH= | ||
MONGO_URL=mongodb+srv://user:dbUserPassword@snappercluster.i3fur.mongodb.net/?retryWrites=true&w=majority&appName=SnapperCluster; | ||
MONGO_USERNAME="user" | ||
MONGO_PASSWORD="dbUserPassword" | ||
SUPABASE_PASSWORD="9waZ2NQKum6FmP$" | ||
SUPABASE_URL="https://xcgzrcnpyoxwxbjwnfnn.supabase.co" | ||
SUPABASE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhjZ3pyY25weW94d3hianduZm5uIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjU1NTMxOTUsImV4cCI6MjA0MTEyOTE5NX0.NgMdOTtSCbMdxkrzCgNYCyKBSLpzPuyARB8qnn3NKNo" |
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 @@ | ||
import request from 'supertest'; | ||
import express from 'express'; | ||
import pingRoute from '../routes/healthcheck'; // Adjust to the correct file path | ||
|
||
jest.mock('../middlewares/authMiddleware', () => ({ | ||
isAuthenticated: ( | ||
req: express.Request, | ||
res: express.Response, | ||
next: express.NextFunction, | ||
) => { | ||
return next(); | ||
}, | ||
})); | ||
|
||
const app = express(); | ||
const router = express.Router(); | ||
pingRoute(router); | ||
app.use(router); | ||
|
||
describe('GET /ping', () => { | ||
it('should return 200 with "hello: world"', async () => { | ||
const res = await request(app).get('/ping'); | ||
expect(res.status).toBe(200); | ||
expect(res.body).toEqual({ hello: 'world' }); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
import session from 'express-session'; | ||
import MongoStore from 'connect-mongo'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
export const sessionMiddleware = session({ | ||
secret: process.env.SESSION_SECRET || 'your-secret-key', | ||
resave: false, | ||
saveUninitialized: false, | ||
store: MongoStore.create({ | ||
mongoUrl: process.env.MONGO_URL, | ||
collectionName: 'sessions', | ||
}), | ||
cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 }, | ||
}); |
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,4 @@ | ||
import { createClient } from '@supabase/supabase-js'; | ||
import { config } from './config'; | ||
|
||
export const supabase = createClient(config.supabase.url, config.supabase.key); |
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,76 @@ | ||
// import express from 'express'; | ||
// import { supabase } from '../config/supabaseClient'; | ||
// import { createUser } from '../services/userService'; | ||
// import session from 'express-session'; | ||
|
||
// export const register = async (req: express.Request, res: express.Response) => { | ||
// try { | ||
// const { email, password, username } = req.body; | ||
|
||
// if (!email || !password || !username) { | ||
// return res.status(400).json({ error: 'Missing required fields' }); | ||
// } | ||
|
||
// const { data, error } = await supabase.auth.signUp({ email, password }); | ||
|
||
// if (error) { | ||
// console.error('Supabase signUp error:', error.message); | ||
// return res.status(400).json({ error: error.message }); | ||
// } | ||
|
||
// const user = data.user; | ||
// if (!user) { | ||
// console.error('User creation failed: no user returned from Supabase'); | ||
// return res.status(400).json({ error: 'User creation failed' }); | ||
// } | ||
|
||
// await createUser({ email, username, supabaseId: user.id }); | ||
|
||
// req.session.userId = req.session ? user.id : undefined; | ||
|
||
// return res.status(200).json({ message: 'User registered successfully', user }); | ||
// } catch (err) { | ||
// console.error('Registration error:', err); | ||
// return res.status(500).json({ error: 'Internal server error' }); | ||
// } | ||
// }; | ||
|
||
// export const login = async (req: express.Request, res: express.Response) => { | ||
// const { email, password } = req.body; | ||
|
||
// if (!email || !password) { | ||
// return res.status(400).json({ error: 'Missing required fields' }); | ||
// } | ||
|
||
// const { data, error } = await supabase.auth.signInWithPassword({ email, password }); | ||
|
||
// if (error) { | ||
// return res.status(400).json({ error: error.message }); | ||
// } | ||
|
||
// const user = data.user; | ||
|
||
// if (!user) { | ||
// return res.status(400).json({ error: 'Login failed' }); | ||
// } | ||
|
||
// req.session.userId = req.session ? user.id : undefined; | ||
|
||
// return res.status(200).json({ message: 'Login successful', user }); | ||
// }; | ||
|
||
// export const logout = async (req: express.Request, res: express.Response) => { | ||
// const { error } = await supabase.auth.signOut(); | ||
|
||
// if (error) { | ||
// return res.status(400).json({ error: 'Failed to log out' }); | ||
// } | ||
|
||
// req.session.destroy((err) => { | ||
// if (err) { | ||
// return res.status(500).json({ error: 'Failed to destroy session' }); | ||
// } | ||
|
||
// return res.status(200).json({ message: 'Logout successful' }); | ||
// }); | ||
// }; |
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
import express from 'express'; | ||
import { supabase } from '../../config/supabaseClient'; | ||
|
||
export const login = async (req: express.Request, res: express.Response) => { | ||
try { | ||
const { email, password } = req.body; | ||
|
||
if (!email || !password) { | ||
return res | ||
.status(400) | ||
.json({ error: 'Email and password are required.' }); | ||
} | ||
|
||
const { data, error } = await supabase.auth.signInWithPassword({ | ||
email, | ||
password, | ||
}); | ||
|
||
if (error) { | ||
return res | ||
.status(400) | ||
.json({ error: 'Invalid email or password. Please try again.' }); | ||
} | ||
|
||
const user = data.user; | ||
|
||
if (!user) { | ||
return res | ||
.status(500) | ||
.json({ error: 'Login failed. Please try again later.' }); | ||
} | ||
|
||
req.session.userId = req.session ? user.id : undefined; | ||
|
||
return res.status(200).json({ message: 'Login successful.', user }); | ||
} catch (err) { | ||
console.error('Login error:', err); | ||
return res | ||
.status(500) | ||
.json({ error: 'Internal server error during login.' }); | ||
} | ||
}; |
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,29 @@ | ||
import express from 'express'; | ||
import { supabase } from '../../config/supabaseClient'; | ||
|
||
export const logout = async (req: express.Request, res: express.Response) => { | ||
try { | ||
const { error } = await supabase.auth.signOut(); | ||
|
||
if (error) { | ||
return res | ||
.status(400) | ||
.json({ error: 'Failed to log out. Please try again later.' }); | ||
} | ||
|
||
req.session.destroy((err) => { | ||
if (err) { | ||
return res | ||
.status(500) | ||
.json({ error: 'Failed to end session. Please try again later.' }); | ||
} | ||
|
||
return res.status(200).json({ message: 'Logout successful.' }); | ||
}); | ||
} catch (err) { | ||
console.error('Logout error:', err); | ||
return res | ||
.status(500) | ||
.json({ error: 'Internal server error during logout.' }); | ||
} | ||
}; |
Oops, something went wrong.