Spaces:
Running
Running
assafvayner HF Staff
fix(app): 503 on storage failures, validated currency, lock release on shutdown, per-IP login limit, unit-only npm test
e830ad4 Download src/lib/server/auth/guards.ts from assafvayner/splitwise: direct link, hf CLI and curl.
- Browser
- Download file 729 Bytes
-
https://huggingface.co/spaces/assafvayner/splitwise/resolve/main/src/lib/server/auth/guards.ts
- Command line
-
hf download hf://spaces/assafvayner/splitwise/src/lib/server/auth/guards.ts
-
curl -L -o guards.ts https://huggingface.co/spaces/assafvayner/splitwise/resolve/main/src/lib/server/auth/guards.ts
729 Bytes
| import { error } from '@sveltejs/kit'; | |
| import type { User } from '../../domain/types'; | |
| import { UsersRepo, UserValidationError } from '../users/repository'; | |
| /** Every admin load/action calls this; the route gate in hooks is defense in depth, not the check. */ | |
| export function requireAdmin(locals: App.Locals): User { | |
| const user = locals.user; | |
| if (!user || user.role !== 'admin') error(403, 'Admins only'); | |
| return user; | |
| } | |
| /** Admin mutations may only target members: the admin's own account is managed via /me. */ | |
| export function requireMemberTarget(users: UsersRepo, id: string): User { | |
| const user = users.byId(id); | |
| if (!user || user.role !== 'member') throw new UserValidationError('Unknown user', 'id'); | |
| return user; | |
| } | |