Spaces:
Running
Running
Download src/auth/authMiddleware.js from hari7775/resume-server: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/spaces/hari7775/resume-server/resolve/main/src/auth/authMiddleware.js
- Command line
-
hf download hf://spaces/hari7775/resume-server/src/auth/authMiddleware.js
-
curl -L -o authMiddleware.js https://huggingface.co/spaces/hari7775/resume-server/resolve/main/src/auth/authMiddleware.js
1.35 kB
| import { admin } from './firebase.js'; | |
| // ββ Strict Authentication Middleware ββ | |
| export async function requireStrictAuth(req, res, next) { | |
| const authHeader = req.headers.authorization; | |
| if (!authHeader || !authHeader.startsWith('Bearer ')) { | |
| return res.status(401).json({ | |
| error: 'UNAUTHORIZED', | |
| message: 'Missing Authorization Bearer token header.' | |
| }); | |
| } | |
| const token = authHeader.substring(7).trim(); | |
| try { | |
| const decodedToken = await admin.auth().verifyIdToken(token); | |
| const uid = decodedToken.uid; | |
| const signInProvider = decodedToken.firebase?.sign_in_provider || ''; | |
| const isAnonymous = signInProvider === 'anonymous'; | |
| if (isAnonymous) { | |
| return res.status(403).json({ | |
| error: 'ANONYMOUS_NOT_ALLOWED', | |
| message: 'Guest/anonymous accounts cannot generate or download resumes. Please sign in or create an account to proceed.' | |
| }); | |
| } | |
| req.user = { | |
| uid, | |
| email: decodedToken.email | |
| }; | |
| next(); | |
| } catch (error) { | |
| console.error('[Auth Error]', error.message); | |
| return res.status(401).json({ | |
| error: 'UNAUTHORIZED', | |
| message: 'Invalid or expired Firebase authentication token.' | |
| }); | |
| } | |
| } | |