Created
March 14, 2023 00:46
-
-
Save readysetawesome/80a3d95dcacf5c0cd1e086b005b370d5 to your computer and use it in GitHub Desktop.
patch to allow setting cloudflare pages access aud from env vars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/functions/_middleware.ts b/functions/_middleware.ts | |
index 9d5ae42..8f46b34 100644 | |
--- a/functions/_middleware.ts | |
+++ b/functions/_middleware.ts | |
@@ -1,8 +1,20 @@ | |
import cloudflareAccessPlugin from "@cloudflare/pages-plugin-cloudflare-access"; | |
-export const onRequest = ({ env }) => { | |
- return cloudflareAccessPlugin({ | |
- domain: "https://timely-tasker.cloudflareaccess.com", | |
- aud: env.AUDIENCE, | |
- }); | |
+interface Env { | |
+ AUDIENCE: string; | |
} | |
+ | |
+export const onRequest: PagesFunction<Env> = (context) => { | |
+ const aud = context.env.AUDIENCE; | |
+ if (typeof aud !== 'string') { | |
+ // must be local dev mode, just pass through | |
+ // TODO: Stub local dev user auth in the middeware/functions | |
+ return context.next(); | |
+ } else { | |
+ return cloudflareAccessPlugin({ | |
+ domain: "https://timely-tasker.cloudflareaccess.com", | |
+ aud: aud | |
+ })(context); | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment