mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-25 20:02:47 +00:00
21 lines
600 B
TypeScript
21 lines
600 B
TypeScript
import { Request, Response, NextFunction } from 'express';
|
|
|
|
const authMiddleware = (req: Request, res: Response, next: NextFunction) => {
|
|
const bearerHeader = req.headers['authorization'];
|
|
|
|
if (bearerHeader) {
|
|
console.log("bearerHeader:" + bearerHeader);
|
|
const bearer = bearerHeader.split(' ');
|
|
const bearerToken = bearer[1];
|
|
|
|
if (bearerToken === process.env.ACCESS_TOKEN) {
|
|
next();
|
|
} else {
|
|
res.status(403).json({ message: 'Invalid token' });
|
|
}
|
|
} else {
|
|
res.status(401).json({ message: 'Bearer token not found' });
|
|
}
|
|
};
|
|
|
|
export default authMiddleware; |