wip: try to send cookie

This commit is contained in:
eneller
2026-03-08 20:39:04 +01:00
parent c9a2cd8d66
commit 6eca085b6e
5 changed files with 22 additions and 10 deletions

View File

@@ -1,8 +1,10 @@
# FakeMoney # FakeMoney
A PayPal-like payment processor for virtual money, intended to be used for simulation games. A PayPal-like payment processor for virtual money, intended to be used for simulation games.
## Frontend ## Development
### Frontend
Is written in angular + bootstrap. Is written in angular + bootstrap.
## Backend ### Backend
Uses NextJS + PostgreSQL. Uses NextJS + PostgreSQL with JWT as cookies.

View File

@@ -65,6 +65,9 @@
"defaultConfiguration": "production" "defaultConfiguration": "production"
}, },
"serve": { "serve": {
"options": {
"proxyConfig": "proxy.json"
},
"builder": "@angular/build:dev-server", "builder": "@angular/build:dev-server",
"configurations": { "configurations": {
"production": { "production": {

8
client/proxy.json Normal file
View File

@@ -0,0 +1,8 @@
{
"/api": {
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true,
"withCredentials": true
}
}

View File

@@ -7,6 +7,7 @@ import { db, testConnection } from "./util/db";
import { logger } from "./util/logging"; import { logger } from "./util/logging";
const app: Express = express(); const app: Express = express();
// TODO replace with frontend URL
app.use(cors({ origin: 'http://localhost:4200', credentials: true})); app.use(cors({ origin: 'http://localhost:4200', credentials: true}));
app.use(cookieParser()); app.use(cookieParser());
app.use(express.json()); app.use(express.json());
@@ -20,12 +21,12 @@ app.use('/api/auth', authRouter);
const PORT: number = parseInt(process.env.PORT as string) || 3000; const PORT: number = parseInt(process.env.PORT as string) || 3000;
// Start server after DB connection is established
async function startServer() { async function startServer() {
await testConnection(); // Test DB connection first await testConnection();
// Sync models (use migrations in production!) // Sync models (use migrations in production!)
await db.sync({ alter: true }); // Use { force: true } to drop and recreate tables (development only!) // Use { force: true } to drop and recreate tables (development only!)
await db.sync({ alter: true });
app.listen(PORT, () => { app.listen(PORT, () => {
logger.info(`🚀 Backend Server running on http://localhost:${PORT}`); logger.info(`🚀 Backend Server running on http://localhost:${PORT}`);

View File

@@ -17,11 +17,9 @@ router.post('/login', async (req, res) => {
// successfully authenticated // successfully authenticated
res.cookie('jwt', 'toekn', { res.cookie('jwt', 'toekn', {
/*
httpOnly: true, // Prevent XSS httpOnly: true, // Prevent XSS
secure: true, // HTTPS only secure: false, // HTTPS only
sameSite: 'strict', // CSRF protection sameSite: 'lax', // CSRF protection
*/
maxAge: 86400000, // 1 day maxAge: 86400000, // 1 day
}); });
res.json({ message: 'Logged in successfully' }); res.json({ message: 'Logged in successfully' });