init commit

This commit is contained in:
2025-11-07 22:24:40 +01:00
parent a5373286bf
commit 15b8f36d4d
217 changed files with 168229 additions and 0 deletions

31
server/middlewares/auth.ts Executable file
View File

@@ -0,0 +1,31 @@
import myError from '../api/myError'
export function isAuthorized (req, res, next) {
if (!req.session.userId) {
const error = new myError(
'unauthorized cookie',
401,
1,
'خطا رخ داد!',
'لطفا برای ادامه لاگین کنید!'
)
next(error)
} else {
next()
}
}
export function isAdmin (req, res, next) {
if (!req.session.adminId) {
const error = new myError(
'unauthorized',
401,
3,
'خطا رخ داد!',
'شما اجازه دسترسی ندارید!'
)
next(error)
} else {
next()
}
}