Skip to content

Commit

Permalink
feat: support cloudflare access when access remote storage
Browse files Browse the repository at this point in the history
  • Loading branch information
RihanArfan committed Oct 26, 2024
1 parent 50cee14 commit 6956225
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export interface HubConfig {
userToken?: string
env?: string
version?: string
cloudflareAccess?: {
clientId: string
clientSecret: string
}

ai?: boolean
analytics?: boolean
Expand Down Expand Up @@ -310,7 +314,11 @@ export async function setupRemote(_nuxt: Nuxt, hub: HubConfig) {
const remoteManifest = hub.remoteManifest = await $fetch<HubConfig['remoteManifest']>('/api/_hub/manifest', {
baseURL: hub.projectUrl as string,
headers: {
authorization: `Bearer ${hub.projectSecretKey || hub.userToken}`
authorization: `Bearer ${hub.projectSecretKey || hub.userToken}`,
...(hub.cloudflareAccess?.clientId && hub.cloudflareAccess?.clientSecret && {
'CF-Access-Client-Id': hub.cloudflareAccess?.clientId,
'CF-Access-Client-Secret': hub.cloudflareAccess?.clientSecret
})
}
})
.catch(async (err) => {
Expand Down
5 changes: 5 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export default defineNuxtModule<ModuleOptions>({
hyperdrive: {},
// @ts-expect-error nitro.cloudflare.wrangler is not yet typed
compatibilityFlags: nuxt.options.nitro.cloudflare?.wrangler?.compatibility_flags
},
// Cloudflare Access
cloudflareAccess: {
clientId: process.env.NUXT_HUB_CLOUDFLARE_ACCESS_CLIENT_ID || null,
clientSecret: process.env.NUXT_HUB_CLOUDFLARE_ACCESS_CLIENT_SECRET || null
}
})
runtimeConfig.hub = hub
Expand Down
16 changes: 16 additions & 0 deletions src/types/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,20 @@ export interface ModuleOptions {
[key: string]: string
}
}
/**
* Cloudflare Access authentication for remote storage.
* @see https://hub.nuxt.com/recipes/cloudflare-access
*/
cloudflareAccess?: {
/**
* The client ID for Cloudflare Access.
* @default process.env.NUXT_HUB_CLOUDFLARE_ACCESS_CLIENT_ID
*/
clientId?: string
/**
* The client secret for Cloudflare Access.
* @default process.env.NUXT_HUB_CLOUDFLARE_ACCESS_CLIENT_SECRET
*/
clientSecret?: string
}
}

0 comments on commit 6956225

Please sign in to comment.