11import jwt from 'jsonwebtoken'
22import type { Request } from 'express'
3- import { getCacheConfig } from '../storage/config'
3+ import { authProxyHeaderName , getCacheConfig } from '../storage/config'
44import { createUser , getUser , getUserById } from '../storage/mongo'
55import { Status , UserRole } from '../storage/model'
66import type { AuthJwtPayload } from '../types'
@@ -10,17 +10,17 @@ async function auth(req, res, next) {
1010
1111 if ( config . siteConfig . authProxyEnabled ) {
1212 try {
13- const username = req . header ( 'X-Email' )
13+ const username = req . header ( authProxyHeaderName )
1414 if ( ! username ) {
15- res . send ( { status : 'Unauthorized' , message : ' Please config auth proxy (usually is nginx) add set proxy header X-Email.' , data : null } )
15+ res . send ( { status : 'Unauthorized' , message : ` Please config auth proxy (usually is nginx) add set proxy header ${ authProxyHeaderName } .` , data : null } )
1616 return
1717 }
1818 const user = await getUser ( username )
1919 req . headers . userId = user . _id . toString ( )
2020 next ( )
2121 }
2222 catch ( error ) {
23- res . send ( { status : 'Unauthorized' , message : error . message ?? ' Please config auth proxy (usually is nginx) add set proxy header X-Email.' , data : null } )
23+ res . send ( { status : 'Unauthorized' , message : error . message ?? ` Please config auth proxy (usually is nginx) add set proxy header ${ authProxyHeaderName } .` , data : null } )
2424 }
2525 return
2626 }
@@ -52,7 +52,11 @@ async function getUserId(req: Request): Promise<string | undefined> {
5252 try {
5353 const config = await getCacheConfig ( )
5454 if ( config . siteConfig . authProxyEnabled ) {
55- const username = req . header ( 'X-Email' )
55+ const username = req . header ( authProxyHeaderName )
56+ if ( ! username ) {
57+ globalThis . console . error ( `Please config auth proxy (usually is nginx) add set proxy header ${ authProxyHeaderName } .` )
58+ return null
59+ }
5660 let user = await getUser ( username )
5761 if ( user == null ) {
5862 const isRoot = username . toLowerCase ( ) === process . env . ROOT_USER
0 commit comments