-
Notifications
You must be signed in to change notification settings - Fork 67
Description
Hi team,
[updated issue]
I am struggling to find or build a working example of custom JWT auth with ConvexProviderWithAuth + providing a custom useAuth.
My latest attempt to make it work fails with an infinite loop of refetching the JWT, likely a race condition / stale cache or something similar.
Minimal repro: https://github.com/antoineol/convex-jwt/tree/loop-refetch
git clone https://github.com/antoineol/convex-jwt.git
cd convex-jwt
git checkout loop-refetch
bun install
bun dev
Behavior you get: open localhost:3000 and check the network tab + server logs: it continuously refetches the token. The sync websocket also loops.
But it works well with the lower-level convex.setAuth(fetchToken): https://github.com/antoineol/convex-jwt/tree/working-custom-jwt-with-setauth
Thanks a lot for your help! 🙏
More context: I'm trying to add a nextjs + convex app next to our product existing app (Rails + devise + postgres) with live sync, to progressively migrate some pages while preserving a nice user navigation experience. It works great, except the auth.
[original issue]
I am trying to make the custom JWT auth work, but the auth state remains desperately unauthenticated, despite following strictly the doc steps. There is no error, nothing else, so I suspect a step is missing, but I can't find which one.
Minimal repro: https://github.com/antoineol/convex-jwt
git clone https://github.com/antoineol/convex-jwt.git
cd convex-jwt
bun install
bun dev
FYI, steps followed to build it:
- nextjs quickstart: https://docs.convex.dev/quickstart/nextjs
- Add a minimal JWT generation + JWKS URL & data URL with jose library
- custom JWT doc steps: https://docs.convex.dev/auth/advanced/custom-jwt
- Custom OIDC > Client-side integration steps to add the hooks
- A small piece of UI to show the JWT hook + the convex hook
PS: .env.local is versioned on purpose with RSA public/private key for the demo, so that all pieces are there to reproduce.
I have the feeling the issue is related to the useProviderXAuth (or useAuthFromProviderX) that is required to have a specific behavior (not documented here), like prefetching the token without waiting for an explicit call to fetchAccessToken / getToken. But maybe not with an initial value either? I'm still trying to clarify it.