I have an issue with netlify + vite + supertokens.
Basically apiUrl is not stripped from the URL passed to the api functions, making supertokens fail routing on the api side.
I can reproduce the issue locally using
netlify dev that expose a 8888 port and both a web/api at 8910 and 8911 respectively.
Maybe an equivalent configuration is missing on the FE of netlify ?
rewrite: (path) => path.replace(rwConfig.web.apiUrl, '') in @redwodjs/vite/src/index.ts
Would it be possible to provide more details of the problem you’re seeing here? As in:
- what call is failing exactly
- where are you calling the endpoint from?
- maybe the relevant part from your netlify deployment
- is it just a regular setup of supertokens (with yarn rw setup…)?
Appreciate the debugging here, but not enough information to help! However I suspect it’s not related to the stripping of the
apiUrl though, that may be more to do with the netlify CLI than your actual problem!
I also note the URLs you posted: http://localhost:8910/.netlify/functions/auth/jwt/jwks.json - so a jwt folder that nests a json file. I don’t believe this will work (without additional configuration), because Netlify will only pick up functions defined one level deep, for example:
│ ├── auth.ts ✅
│ └── graphql.ts ✅
│ ├── bazinga ✅
│ │ └── bazinga.ts
│ │ └── nested
│ │ └── nested.js ❌
I believe our server behaves the same way too.
Guess at solving the issue
I’m not super familiar with supertokens (not used it myself yet) - but if this is just the standard setup, maybe you’ll need to add a redirect to send all requests from
I’m imagining the way it works is that it intercepts all requests to the /auth endpoint, and handles it internally.
Thanks for looking into this. It seems that indeed supertokens intercepts the auth calls and routes internally (including the jwks url).
- All calls to /auth fails because supertokens expects the path to start with /auth and not /.netlify/functions/auth
- I have the same issue on a fresh create-redwood + supertokens + netlify install. I use netlify dev to run locally the stack
- The same issue happens on a netlify deploy or netlify dev
- Temporary fix that works for me in the context of netlify deploy/dev is to replace apiBasePath config variable in the api supertokens init from /auth to /.netlify/functions/auth
Hmmm! Thanks, yeah this is an odd one.
Do you think it could be something to do with this env variable?
SUPERTOKENS_JWKS_URL - in the docs it does have an example SuperTokens Authentication | RedwoodJS Docs
Remember to check the value in your Netlify.toml or dashboard!
Please do let me know if this helps, otherwise we can open an issue and I can debug the deployment with your reproduction
I used the JWKS_URL as an example, but all supertokens auth queries fail (they all go through the same apiBasePath URL check).
Supertokens has released an updated major version of their front/back packages. I see some work on accepting multiple front domains (feat: Refactor app info type to allow adding multiple website domains by nkshah2 · Pull Request #706 · supertokens/supertokens-node · GitHub). Maybe they addressed this backend concern too.