mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2026-04-28 11:17:38 +02:00
unified auth exceptions, added syncdata and selfinfo
This commit is contained in:
@@ -25,9 +25,18 @@ import type { Database } from 'better-sqlite3'
|
||||
import logger from '../utils/logger'
|
||||
import dbtools from '../utils/dbtools'
|
||||
|
||||
const EXCEPTIONS = [
|
||||
'/api/registerscript',
|
||||
'/api/login',
|
||||
'/api/validationtoken',
|
||||
'/api/syncp2pdata',
|
||||
'/api/selfInfo',
|
||||
'/favicon.ico',
|
||||
'/img/frylabs-logo_large_transparent.png',
|
||||
] as const
|
||||
|
||||
interface Options {
|
||||
userDB: Database
|
||||
exceptions: Array<string>
|
||||
}
|
||||
|
||||
export const testUser: User = {
|
||||
@@ -55,17 +64,11 @@ function renderLogin(req: Request, res: Response) {
|
||||
}
|
||||
|
||||
export default function (options: Options): RequestHandler {
|
||||
const {
|
||||
userDB,
|
||||
exceptions,
|
||||
}: {
|
||||
userDB: Database
|
||||
exceptions: string[]
|
||||
} = options
|
||||
const { userDB } = options
|
||||
|
||||
return function (req: Request, res: Response, next: NextFunction) {
|
||||
const sessionID = req.cookies.sessionID
|
||||
const isException = exceptions.some((exc) => {
|
||||
const isException = EXCEPTIONS.some((exc) => {
|
||||
return req.originalUrl.split('?')[0] === exc
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user