1
1
import jwt from 'jsonwebtoken'
2
2
import type { Request } from 'express'
3
- import { getCacheConfig } from '../storage/config'
3
+ import { authProxyHeaderName , getCacheConfig } from '../storage/config'
4
4
import { createUser , getUser , getUserById } from '../storage/mongo'
5
5
import { Status , UserRole } from '../storage/model'
6
6
import type { AuthJwtPayload } from '../types'
@@ -10,17 +10,17 @@ async function auth(req, res, next) {
10
10
11
11
if ( config . siteConfig . authProxyEnabled ) {
12
12
try {
13
- const username = req . header ( 'X-Email' )
13
+ const username = req . header ( authProxyHeaderName )
14
14
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 } )
16
16
return
17
17
}
18
18
const user = await getUser ( username )
19
19
req . headers . userId = user . _id . toString ( )
20
20
next ( )
21
21
}
22
22
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 } )
24
24
}
25
25
return
26
26
}
@@ -52,7 +52,11 @@ async function getUserId(req: Request): Promise<string | undefined> {
52
52
try {
53
53
const config = await getCacheConfig ( )
54
54
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
+ }
56
60
let user = await getUser ( username )
57
61
if ( user == null ) {
58
62
const isRoot = username . toLowerCase ( ) === process . env . ROOT_USER
0 commit comments