unified auth exceptions, added syncdata and selfinfo

This commit is contained in:
mrfry 2023-04-12 09:27:44 +02:00
parent ac01455510
commit d99bb0fedc
5 changed files with 13 additions and 30 deletions

View file

@ -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
})

View file

@ -83,15 +83,6 @@ function GetApp(): ModuleType {
app.use(
auth({
userDB: userDB,
exceptions: [
'/favicon.ico',
'/api/register',
'/api/login',
'/api/postfeedback',
'/api/fosuploader',
'/api/badtestsender',
'/api/validationtoken',
],
})
)
app.use(

View file

@ -1037,7 +1037,7 @@ function setup(data: SubmoduleData): Submodule {
app.get('/syncp2pdata', (req: Request, res: Response) => {
logger.LogReq(req)
const user = req.session.user
if (user.id !== 1) {
if (!user || user.id !== 1) {
res.json({
status: 'error',
msg: 'only user 1 can call this EP',

View file

@ -52,7 +52,6 @@ function GetApp(): ModuleType {
app.use(
auth({
userDB: userDB,
exceptions: ['/favicon.ico'],
})
)
app.use((req: Request, _res, next) => {

View file

@ -53,16 +53,6 @@ function GetApp(): ModuleType {
app.use(
auth({
userDB: userDB,
exceptions: [
'/favicon.ico',
'/img/frylabs-logo_large_transparent.png',
'/api/register',
'/api/login',
'/api/postfeedback',
'/api/fosuploader',
'/api/badtestsender',
'/api/validationtoken',
],
})
)
app.use((req: Request, _res, next) => {