@@ -5,7 +5,8 @@ import session from "express-session";
55import passport from "passport" ;
66import pg from "pg" ;
77import { createRequire } from "module" ;
8- import prisma from "./auth.js" ;
8+ import prisma from "./prismaClient.js" ;
9+ import "./auth.js" ;
910import requireAuth from "./middleware/requireAuth.js" ;
1011import { handleOrderFiscalization } from "./fira.js" ;
1112import { getSessionRange } from './utils/sessionHelper.js' ;
@@ -37,7 +38,11 @@ app.use(
3738 secret : process . env . SESSION_SECRET || "dev_secret" ,
3839 resave : false ,
3940 saveUninitialized : false ,
40- cookie : { secure : false } , // dev only
41+ cookie : {
42+ secure : process . env . NODE_ENV === "production" ,
43+ httpOnly : true ,
44+ sameSite : "lax"
45+ } ,
4146 } )
4247) ;
4348
@@ -53,10 +58,10 @@ app.get("/api/health", async (req, res) => {
5358 const transactionCount = await prisma . transaction . count ( ) ;
5459 const receiptCount = await prisma . receipt . count ( ) ;
5560
56- console . log ( ` ✅ Database OK!` ) ;
57- console . log ( ` Users: ${ userCount } ` ) ;
58- console . log ( ` Transactions: ${ transactionCount } ` ) ;
59- console . log ( ` Receipts: ${ receiptCount } ` ) ;
61+ console . log ( `✅ Database OK!` ) ;
62+ console . log ( `Users: ${ userCount } ` ) ;
63+ console . log ( `Transactions: ${ transactionCount } ` ) ;
64+ console . log ( `Receipts: ${ receiptCount } ` ) ;
6065
6166 res . json ( {
6267 status : "OK" ,
@@ -250,7 +255,7 @@ app.get("/api/receipts", requireAuth, async (req, res) => {
250255 }
251256} ) ;
252257
253- app . get ( '/api/receipts/current-session' , async ( req , res ) => {
258+ app . get ( '/api/receipts/current-session' , requireAuth , async ( req , res ) => {
254259 try {
255260 const now = new Date ( ) ;
256261 const start = new Date ( now ) ;
@@ -286,7 +291,7 @@ app.get('/api/receipts/current-session', async (req, res) => {
286291
287292// ========== RECEIPTS API UPDATES ==========
288293
289- app . get ( '/api/receipts/active-dates' , async ( req , res ) => {
294+ app . get ( '/api/receipts/active-dates' , requireAuth , async ( req , res ) => {
290295 try {
291296 const receipts = await prisma . receipt . findMany ( {
292297 select : { createdAt : true }
@@ -306,7 +311,7 @@ app.get('/api/receipts/active-dates', async (req, res) => {
306311 }
307312} ) ;
308313
309- app . get ( '/api/receipts/range' , async ( req , res ) => {
314+ app . get ( '/api/receipts/range' , requireAuth , async ( req , res ) => {
310315 const { from, to } = req . query ;
311316
312317 try {
@@ -910,7 +915,7 @@ app.put('/api/settings/active-location', requireAuth, async (req, res) => {
910915} ) ;
911916
912917// GET all prodajna mjesta
913- app . get ( '/api/prodajna-mjesta' , async ( req , res ) => {
918+ app . get ( '/api/prodajna-mjesta' , requireAuth , async ( req , res ) => {
914919 try {
915920 const locations = await prisma . prodajnoMjesto . findMany ( ) ;
916921 const safeLocations = locations . map ( loc => {
@@ -928,7 +933,7 @@ app.get('/api/prodajna-mjesta', async (req, res) => {
928933} ) ;
929934
930935// POST new prodajno mjesto
931- app . post ( '/api/prodajna-mjesta' , async ( req , res ) => {
936+ app . post ( '/api/prodajna-mjesta' , requireAuth , async ( req , res ) => {
932937 try {
933938 const { name, businessSpace, paymentDevice, firaApiKey, active } = req . body ;
934939
@@ -960,7 +965,7 @@ app.post('/api/prodajna-mjesta', async (req, res) => {
960965} ) ;
961966
962967// PUT (update) prodajno mjesto
963- app . put ( '/api/prodajna-mjesta/:id' , async ( req , res ) => {
968+ app . put ( '/api/prodajna-mjesta/:id' , requireAuth , async ( req , res ) => {
964969 const { id } = req . params ;
965970 const { name, businessSpace, paymentDevice, firaApiKey, active } = req . body ;
966971 try {
@@ -979,7 +984,7 @@ app.put('/api/prodajna-mjesta/:id', async (req, res) => {
979984} ) ;
980985
981986// DELETE prodajno mjesto
982- app . delete ( '/api/prodajna-mjesta/:id' , async ( req , res ) => {
987+ app . delete ( '/api/prodajna-mjesta/:id' , requireAuth , async ( req , res ) => {
983988 const { id } = req . params ;
984989 try {
985990 await prisma . prodajnoMjesto . delete ( {
0 commit comments