feat: bootstrap backend API, schema and forgejo task issues
This commit is contained in:
parent
77e837cc25
commit
09ea388190
15 changed files with 1557 additions and 0 deletions
15
backend/src/middleware/auth.js
Normal file
15
backend/src/middleware/auth.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import jwt from 'jsonwebtoken';
|
||||
|
||||
export const requireAuth = (req, res, next) => {
|
||||
const authHeader = req.headers.authorization || '';
|
||||
const token = authHeader.startsWith('Bearer ') ? authHeader.slice(7) : null;
|
||||
|
||||
if (!token) return res.status(401).json({ error: 'Missing token' });
|
||||
|
||||
try {
|
||||
req.user = jwt.verify(token, process.env.JWT_SECRET);
|
||||
next();
|
||||
} catch {
|
||||
res.status(401).json({ error: 'Invalid token' });
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue