Skip to content

Commit 76d13e6

Browse files
committed
fix(auth): Ensure admin role verification occurs after user data retrieval
1 parent 2daebaa commit 76d13e6

2 files changed

Lines changed: 10 additions & 17 deletions

File tree

docker-compose.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
# Commercify API Backend
33
commercify-api:
4-
image: ghcr.io/zenfulcode/commercifygo:v2-dev
4+
image: ghcr.io/zenfulcode/commercifygo:v0.0.5-beta
55
ports:
66
- '6091:6091'
77
environment:
@@ -44,7 +44,7 @@ services:
4444
- MOBILEPAY_CLIENT_ID=${MOBILEPAY_CLIENT_ID:-}
4545
- MOBILEPAY_CLIENT_SECRET=${MOBILEPAY_CLIENT_SECRET:-}
4646
- MOBILEPAY_WEBHOOK_URL=${MOBILEPAY_WEBHOOK_URL:-}
47-
- MOBILEPAY_PAYMENT_DESCRIPTION=${MOBILEPAY_PAYMENT_DESCRIPTION:-Commercify Store Purchase}
47+
- MOBILEPAY_PAYMENT_DESCRIPTION=${MOBILEPAY_PAYMENT_DESCRIPTION:-Commercify Store Purchase}''
4848

4949
# Return URL
5050
- RETURN_URL=${RETURN_URL:-http://localhost:3000/payment/complete}
@@ -93,18 +93,11 @@ services:
9393
- NODE_ENV=production
9494
- PORT=3000
9595
- HOST=0.0.0.0
96-
- ORIGIN=https://e070-2a05-f6c6-5509-0-9848-7eb2-e94f-832f.ngrok-free.app
97-
- API_BASE_URL_DEV=http://commercify-api:6091/api
98-
- API_BASE_URL_PROD=http://commercify-api:6091/api
96+
- API_BASE_URL_DEV=http://commercify-api
97+
- API_BASE_URL_PROD=http://commercify-api
9998
depends_on:
10099
- commercify-api
101100
restart: unless-stopped
102-
healthcheck:
103-
test: ['CMD', 'curl', '-f', 'http://localhost:3000/health']
104-
interval: 60s
105-
timeout: 10s
106-
retries: 3
107-
start_period: 40s
108101
networks:
109102
- commercify-network
110103

src/hooks.server.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ const handleAuth: Handle = async ({ event, resolve }) => {
2323
name: `${userResponse.firstName} ${userResponse.lastName}`,
2424
role: userResponse.role as 'admin'
2525
};
26+
27+
// Verify user has admin role (from validated user data)
28+
if (event.locals.user.role !== 'admin') {
29+
console.log('User does not have admin role:', event.locals.user.role);
30+
throw redirect(303, '/login');
31+
}
2632
} catch (error) {
2733
event.cookies.delete('auth_token', { path: '/' });
2834
event.cookies.delete('user_role', { path: '/' });
2935
}
30-
31-
// Verify user has admin role (from validated user data)
32-
if (event.locals.user?.role !== 'admin') {
33-
console.log('User does not have admin role:', event.locals.user!.role);
34-
throw redirect(303, '/login');
35-
}
3636
}
3737

3838
return resolve(event);

0 commit comments

Comments
 (0)