mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
Permission System (#47)
* feat(api): permissions system Adds a permission system for isAuthenticated middleware. Also adds user CRUD.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { getRepository } from 'typeorm';
|
||||
import { User } from '../entity/User';
|
||||
import { Permission } from '../lib/permissions';
|
||||
|
||||
export const checkUser: Middleware = async (req, _res, next) => {
|
||||
if (req.session?.userId) {
|
||||
@@ -16,13 +17,18 @@ export const checkUser: Middleware = async (req, _res, next) => {
|
||||
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();
|
||||
}
|
||||
export const isAuthenticated = (
|
||||
permissions?: Permission | Permission[]
|
||||
): Middleware => {
|
||||
const authMiddleware: Middleware = (req, res, next) => {
|
||||
if (!req.user || !req.user.hasPermission(permissions ?? 0)) {
|
||||
res.status(403).json({
|
||||
status: 403,
|
||||
error: 'You do not have permisson to access this endpoint',
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
};
|
||||
return authMiddleware;
|
||||
};
|
||||
|
Reference in New Issue
Block a user