UNPKG

bluesky-oauth-kit

Version:

A complete OAuth backend implementation for Bluesky

21 lines (16 loc) 660 B
const jwt = require('jsonwebtoken'); const authenticateToken = (req, res, next) => { const token = req.headers['authorization']?.split(' ')[1] || (process.env.OAUTH_USE_COOKIES === 'true' && req.cookies?.token); if (!token) { return res.status(401).json({ error: 'Access denied. No token provided.' }); } try { const user = jwt.verify(token, process.env.OAUTH_JWT_SECRET); req.auth = { user }; // Keep both for backwards compatibility req.user = user; next(); } catch (err) { res.status(403).json({ error: 'Invalid or expired token.' }); } }; module.exports = { authenticateToken };