@@ -17,12 +17,12 @@ export const GET: APIRoute = async ({ request, cookies }) => {
1717 try {
1818 const domain = request . headers . get ( "Host" ) ;
1919 if ( ! domain ) {
20- throw new Error ( ) ;
20+ throw new Error ( "Could not determine domain." ) ;
2121 }
2222
2323 const path = request . headers . get ( "Path" ) ;
2424 if ( ! path ) {
25- throw new Error ( ) ;
25+ throw new Error ( "Could not determine domain." ) ;
2626 }
2727
2828 const ip = request . headers . get ( "X-Forwarded-For" ) ;
@@ -33,11 +33,11 @@ export const GET: APIRoute = async ({ request, cookies }) => {
3333 const timestamp = cookies . get ( "xnode_auth_timestamp" ) ?. value ;
3434
3535 if ( ! isHex ( signature ) ) {
36- throw new Error ( ) ;
36+ throw new Error ( `Signature ${ signature } is not valid hex.` ) ;
3737 }
3838 if ( ! timestamp || isNaN ( Number ( timestamp ) ) ) {
3939 // add checks if timestamp in the future or too far in the past
40- throw new Error ( ) ;
40+ throw new Error ( `Timestamp ${ timestamp } is not a valid number.` ) ;
4141 }
4242
4343 const validSignature = await verifyXnodeUserEthAddress ( {
@@ -53,16 +53,17 @@ export const GET: APIRoute = async ({ request, cookies }) => {
5353 requestedUser = undefined ;
5454 }
5555
56+ const users = ( [ ] as string [ ] )
57+ . concat ( ip ? [ `ip:${ ip } ` ] : [ ] )
58+ . concat ( requestedUser ? [ requestedUser ] : [ ] ) ;
5659 const user = await hasAccess ( {
57- users : ( [ ] as string [ ] )
58- . concat ( ip ? [ `ip:${ ip } ` ] : [ ] )
59- . concat ( requestedUser ? [ requestedUser ] : [ ] ) ,
60+ users,
6061 domain,
6162 path,
6263 } ) ;
6364
6465 if ( user === undefined ) {
65- throw new Error ( ) ;
66+ throw new Error ( `Access denied for ${ requestedUser } ` ) ;
6667 }
6768
6869 return new Response ( null , {
@@ -72,7 +73,10 @@ export const GET: APIRoute = async ({ request, cookies }) => {
7273 } catch ( err : any ) {
7374 return new Response ( null , {
7475 status : 401 ,
75- headers : corsHeaders ( request . headers ) ,
76+ headers : {
77+ "Xnode-Auth-Deny-Reason" : err . message ,
78+ ...corsHeaders ( request . headers ) ,
79+ } ,
7680 } ) ;
7781 }
7882} ;
0 commit comments