Cloudflare pages Basic Auth middleware
Inspired by Cloudflare’s official Basic Auth guide for Workers and the middleware guide for Pages, I created this _middleware.js
file. This file works when placed in the functions/
folder of your Cloudflare Pages repository.
It leverages the BASIC_USER
(defaulting to “admin”) and BASIC_PASS
(defaulting to “password”) environment variables.
If other middlewares need to be used alongside this, ensure that export const onRequest = [authentication];
is properly configured.