File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -10,17 +10,21 @@ export async function requireNuxtHubAuthorization(event: H3Event) {
1010 return
1111 }
1212
13+ // Check if authorization header is set
1314 const secretKeyOrUserToken = ( getHeader ( event , 'authorization' ) || '' ) . split ( ' ' ) [ 1 ]
1415 if ( ! secretKeyOrUserToken ) {
1516 throw createError ( {
1617 statusCode : 403 ,
1718 message : 'Missing Authorization header'
1819 } )
1920 }
20- const projectKey = process . env . NUXT_HUB_PROJECT_KEY
21+
22+ // Get project key and secret key
23+ const env = event . context . cloudflare ?. env || process . env || { }
24+ const projectKey = env . NUXT_HUB_PROJECT_KEY
2125
2226 // Self-hosted NuxtHub project, user has to set a secret key to access the proxy
23- const projectSecretKey = process . env . NUXT_HUB_PROJECT_SECRET_KEY
27+ const projectSecretKey = env . NUXT_HUB_PROJECT_SECRET_KEY
2428 if ( projectSecretKey && secretKeyOrUserToken === projectSecretKey ) {
2529 return
2630 } else if ( projectSecretKey && ! projectKey ) {
@@ -37,7 +41,7 @@ export async function requireNuxtHubAuthorization(event: H3Event) {
3741 }
3842 // Here the secretKey is a user token
3943 await $fetch ( `/api/projects/${ projectKey } ` , {
40- baseURL : process . env . NUXT_HUB_URL || 'https://admin.hub.nuxt.com' ,
44+ baseURL : env . NUXT_HUB_URL || 'https://admin.hub.nuxt.com' ,
4145 method : 'HEAD' ,
4246 headers : {
4347 authorization : `Bearer ${ secretKeyOrUserToken } `
You can’t perform that action at this time.
0 commit comments