@@ -11,8 +11,12 @@ async function auth(req, res, next) {
1111 if ( config . siteConfig . authProxyEnabled ) {
1212 try {
1313 const username = req . header ( 'X-Email' )
14+ if ( ! username ) {
15+ res . send ( { status : 'Unauthorized' , message : 'Please config auth proxy (usually is nginx) add set proxy header X-Email.' , data : null } )
16+ return
17+ }
1418 const user = await getUser ( username )
15- req . headers . userId = user . _id
19+ req . headers . userId = user . _id . toString ( )
1620 next ( )
1721 }
1822 catch ( error ) {
@@ -46,12 +50,7 @@ async function auth(req, res, next) {
4650async function getUserId ( req : Request ) : Promise < string | undefined > {
4751 let token : string
4852 try {
49- // no Authorization info is received withput login
50- if ( ! ( req . header ( 'Authorization' ) as string ) )
51- return null // '6406d8c50aedd633885fa16f'
52- token = req . header ( 'Authorization' ) . replace ( 'Bearer ' , '' )
5353 const config = await getCacheConfig ( )
54-
5554 if ( config . siteConfig . authProxyEnabled ) {
5655 const username = req . header ( 'X-Email' )
5756 let user = await getUser ( username )
@@ -62,6 +61,11 @@ async function getUserId(req: Request): Promise<string | undefined> {
6261 return user . _id . toString ( )
6362 }
6463
64+ // no Authorization info is received without login
65+ if ( ! ( req . header ( 'Authorization' ) as string ) )
66+ return null // '6406d8c50aedd633885fa16f'
67+ token = req . header ( 'Authorization' ) . replace ( 'Bearer ' , '' )
68+
6569 const info = jwt . verify ( token , config . siteConfig . loginSalt . trim ( ) ) as AuthJwtPayload
6670 return info . userId
6771 }
0 commit comments