Hello, I am new to Netlify and Next.js so my apologies if I’m missing something.
I have deployed a version of the site with the role requirements and redirects removed.
- https://lookup-tool.netlify.app/. - splat rule not applied
- https://63a9e15efd2b600008808023--lookup-tool.netlify.app/ - splat rule applied
I have a next.js app deployed on Netlify. This site is configured with GitHub - twilio-labs/netlify-okta-auth: Use Okta as your identity provider with Netlify's Role-based access control with JWT.
- This has me implement redirect to force users to login before they may access the site.
- I also added a redirect to index.html in my netlify.toml to fix an issue with loading images and JS.
That leaves my redirects like this:
# Redirect for dynamic pages in SPA
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
conditions = {Role = ["Everyone"]}
# This redirects unauthenticated users to Okta.
[[redirects]]
from = "/*"
to = "/.netlify/functions/login"
status = 200
force = true
When running locally, the site looks fine.
When deploying on Netlify I receive errors like following for anything under /_next/static/*
Uncaught SyntaxError: Unexpected token '<'
. CSS and JS will not load.
The issue persists even when the only redirect is:
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
I found adding the following to the top of my my netlify.toml redirects fixes the issue, as the files are present in the static directory.
# This makes the chunks and generated CSS work.
[[redirects]]
from = "/_next/*"
to = "/:splat"
status = 200
conditions = {Role = ["Everyone"]}
Downloading a copy of the deployed app then looking at the redirects, I see that Netlify generated
[[redirects]]
from = "/_next/static/*"
to = "/static/:splat"
status = 200
Which is like what I’m doing above. However, it does not seem to apply. My hunch is that my other redirects are interfering as they are a higher priority, but I’m not sure how to work around it while keeping the site restricted by role.
Is re-writing the auto generated rules myself with the Everyone condition above the “correct” way to fix this? I’m concerned about my rules messing up any of the auto-generated rules.
Thanks!