import { getSecret } from '../services/auth-store.js';
export function authMiddleware(req, res, next) {
    const secret = getSecret();
    const openPaths = ['/api/health', '/api/auth/login', '/api/auth/check', '/api/version', '/api/version/check'];
    if (openPaths.includes(req.path))
        return next();
    // Allow public access to mini-app avatar images
    if (/^\/api\/mini-apps\/[^/]+\/avatar$/.test(req.path))
        return next();
    const auth = req.headers.authorization;
    const token = auth?.startsWith('Bearer ') ? auth.slice(7) : '';
    if (token !== secret) {
        res.status(401).json({ error: 'Unauthorized' });
        return;
    }
    next();
}
export function verifyToken(token) {
    const secret = getSecret();
    return (token ?? '') === secret;
}
//# sourceMappingURL=auth.js.map