Give administrators access to all stores and fix store selector

Updates user role checks and store access logic in /api/stores route, adds a fix script.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 4b008663-bd72-492b-b0b6-fa252367e730
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/4b008663-bd72-492b-b0b6-fa252367e730/496YcVj
This commit is contained in:
michaelschal committed 2025-07-19 16:17:15 +00:00
1 parent 87722d8132
commit c909650566
4 files changed
+137 -3

No files matched your search

+14 -3
View File
@@ -198,7 +198,18 @@ export async function registerRoutes(app: Express): Promise<Server> {
app.get('/api/stores', requireAuth, async (req, res) => {
try {
const user = await storage.getUser(req.session.userId!);
if (!user || !user.storeId) {
if (!user) {
return res.status(404).json({ error: "User not found" });
}
// Administrators can access all stores
if (user.role === 'administrator') {
const allStores = await storage.getAllStores();
return res.json(allStores);
}
// Non-administrators only access their assigned store
if (!user.storeId) {
return res.status(404).json({ error: "User store not found" });
}
@@ -232,7 +243,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
targetStoreId = parseInt(storeId as string);
// For non-admin users, verify they can only access their own store
if (user.role !== 'admin' && targetStoreId !== user.storeId) {
if (user.role !== 'administrator' && targetStoreId !== user.storeId) {
return res.status(403).json({ error: "Access denied to this store" });
}
} else {
@@ -264,7 +275,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
// Determine which store to use for the sale
let targetStoreId: number;
if (user.role === 'admin' && req.body.storeId) {
if (user.role === 'administrator' && req.body.storeId) {
// Admin can create sales for any store
targetStoreId = req.body.storeId;
} else {