Keystone-next Admin UI refresh loop on nginx reverse proxy
See original GitHub issueBug report
When I start Keystone-next example projects, for example “examples-next/todo”, all works well when I open the Admin UI in browser directly (using listening port, http://example.com:3000/
).
But when I configure reverse proxy via nginx (https://example.com/
) - I got the infinite loop of page refresh:
Something went wrong.
Unhandled Runtime Error
Error: An error occurred when loading Admin Metadata
Call Stack
useKeystone
webpack-internal:///../../../../packages-next/admin-ui/context/dist/admin-ui.esm.js (415:11)
And in output of keystone-next console - repeating error:
{"level":50,"time":1613990145346,"pid":23190,"hostname":"example.com","name":"graphql","message":"Access denied","locations":[{"line":3,"column":5}],"path":["keystone","adminMeta"],"uid":"cklgg26gj0000w6xxxug1ajz9","name":"GraphQLError","stack":"node_modules/@keystone-next/admin-ui/system/dist/admin-ui.cjs.dev.js:548:19\nrunMicrotasks (<anonymous>)\n"}
To Reproduce
- Start the “examples-next/todo” app.
- Open the Admin UI interface (http://localhost:3000/) directly in browser - all works well, you will see user register form.
- Configure nginx host with https or even http, and reverse proxy to the app port:
location / {
proxy_pass http://localhost:3000/;
# Set additional headers on the upstream request
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
- Try to open the proxied domain (https://example.com/) and got the infinite loop.
- Same problem is with development mode (
yarn dev
).
Full error output:
Unhandled Runtime Error
Error: An error occurred when loading Admin Metadata
Call Stack
useKeystone
webpack-internal:///../../../../packages-next/admin-ui/context/dist/admin-ui.esm.js (415:11)
InitPage
webpack-internal:///../../../../packages-next/auth/pages/InitPage/dist/auth.esm.js (273:90)
renderWithHooks
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (14985:27)
mountIndeterminateComponent
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (17811:13)
beginWork
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (19049:16)
callCallback
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (3945:14)
invokeGuardedCallbackDev
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (3994:16)
invokeGuardedCallback
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (4056:31)
beginWork$1
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (23959:28)
performUnitOfWork
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (22771:12)
workLoopSync
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (22702:22)
renderRootSync
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (22665:7)
performSyncWorkOnRoot
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (22288:18)
flushSyncCallbackQueueImpl/<
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (11327:26)
unstable_runWithPriority
webpack-internal:///../../../../node_modules/react-dom/node_modules/scheduler/cjs/scheduler.development.js (646:12)
runWithPriority$1
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (11276:10)
flushSyncCallbackQueueImpl
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (11322:26)
flushSyncCallbackQueue
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (11309:3)
scheduleUpdateOnFiber
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (21888:9)
dispatchAction
webpack-internal:///../../../../node_modules/react-dom/cjs/react-dom.development.js (16139:26)
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Keycloak AdminURL infinite redirect loop (nginx proxy)
I need the admin console separated to a dedicated, internal, URL, and know to have had this scenario working before. I even copied...
Read more >How to fix a nginx redirection loop? - DigitalOcean
Hello, I'm actually trying to install peertube on my server, but the thing is that there is a redirection loop in my nginx...
Read more >Magento2 with nginix + ssl + varnish admin redirect loop issue
I was facing the same problem and someone tells me to set the base url with https. Set to NO for Use Secure...
Read more >No WP login behind a Reverse Proxy. Just redirect loop.
I can't login to WP behind a Reverse PRoxy. ... Reverse Proxy. Just redirect loop. ... so I'm using my usual nginx-reverse-proxy +...
Read more >Using SSL with redirects from non http causes redirect loop?
However, when I set Nginx to redirect HTTPS to HTTPS, I get a redirect loop where when you visit the website and refresh...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
~new interface is not letting configuration for the express server~
new interface does not have config option to configure express server, I have added a PR to enable
config.server.configureServer
option for this.I was having this similar issue in my local dev environment and found
onethree working solutions to solve it for my case.Solutions:
{ secure: false }
to your keystone session config,NODE_ENV=development
when running keystone,For my case, it was the
secure cookie
not being set that caused the infinite refresh loop (when the db is not initialized) or not being able to login (when the db already has the initial admin user). When it happens, the browser console logs the error message “Error: An error occurred when loading Admin Metadata.”Looking at the login
graphql
response headers will find this line:The “Secure;” statement above declares that the cookie can only be accepted if it was via https request. For production environment, it works fine. But for development environment, we need to use the above mentioned solutions to opt-out of using secure session.