Redirect loop when using the Cloudflare Access Pages plugin

Hi! I’m trying to use the Cloudflare Access plugin to validate JWTs in a Pages project, but as soon as i enable the plugin, i get stuck in a redirect loop, with all the responses having the 302 status code. The redirect loop looks like this:

  • custom-domain.com
  • access-team.cloudflareaccess.com/cdn-cgi/access/login/custom-domain.com?kid=kid&redirect_url=%2F
  • custom-domain.com/cdn-cgi/access/authorized?nonce=nonce
  • custom-domain.com
  • access-team.cloudflareaccess.com/cdn-cgi/access/login/custom-domain.com?kid=kid&redirect_url=%2F
  • custom-domain.com/cdn-cgi/access/authorized?nonce=nonce

Without the plugin, everything works fine, even with Cloudflare Access enabled. It would be awesome if someone could help me with this. Thanks!

Not that it helps much, but I’m getting the same behavior in my Pages project.

In my case I’m trying to chain together multiple middleware functions as follows:

import cloudflareAccessPlugin from "@cloudflare/pages-plugin-cloudflare-access";

// other functions not shown

export const onRequest = [errorHandler, checkEndpoint, cloudflareAccessPlugin({
  domain: 'https://my-access-domain.cloudflareaccess.com',
  aud: 'application-audience'
})];

I’m hoping a Pages dev can help us out :crossed_fingers: