@@ -11,8 +11,12 @@ async function auth(req, res, next) {
11
11
if ( config . siteConfig . authProxyEnabled ) {
12
12
try {
13
13
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
+ }
14
18
const user = await getUser ( username )
15
- req . headers . userId = user . _id
19
+ req . headers . userId = user . _id . toString ( )
16
20
next ( )
17
21
}
18
22
catch ( error ) {
@@ -46,12 +50,7 @@ async function auth(req, res, next) {
46
50
async function getUserId ( req : Request ) : Promise < string | undefined > {
47
51
let token : string
48
52
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 ' , '' )
53
53
const config = await getCacheConfig ( )
54
-
55
54
if ( config . siteConfig . authProxyEnabled ) {
56
55
const username = req . header ( 'X-Email' )
57
56
let user = await getUser ( username )
@@ -62,6 +61,11 @@ async function getUserId(req: Request): Promise<string | undefined> {
62
61
return user . _id . toString ( )
63
62
}
64
63
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
+
65
69
const info = jwt . verify ( token , config . siteConfig . loginSalt . trim ( ) ) as AuthJwtPayload
66
70
return info . userId
67
71
}
0 commit comments