mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
feat(api): initial implementation of the auth system (#30)
Adds the auth system but does not add all required features. They will be handled in other tickets
This commit is contained in:
29
server/middleware/auth.ts
Normal file
29
server/middleware/auth.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { getRepository } from 'typeorm';
|
||||
import { User } from '../entity/User';
|
||||
import { Middleware } from '../types/express';
|
||||
|
||||
export const checkUser: Middleware = async (req, _res, next) => {
|
||||
if (req.session?.userId) {
|
||||
const userRepository = getRepository(User);
|
||||
|
||||
const user = await userRepository.findOne({
|
||||
where: { id: req.session.userId },
|
||||
});
|
||||
|
||||
if (user) {
|
||||
req.user = user;
|
||||
}
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
export const isAuthenticated: Middleware = async (req, res, next) => {
|
||||
if (!req.user) {
|
||||
res.status(403).json({
|
||||
status: 403,
|
||||
error: 'You do not have permisson to access this endpoint',
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user