How to use redirectTo with Convex Auth with Discord
Discord auth allows you to pass a param called
state
, but it strips all other params. I could put the redirectTo
value in the state
param, but then how can I get Convex Auth to see it and redirect to it after authenticating?
It seems Convex Auth puts the value of redirectTo
into a cookie. This doesn't work for my use case, since I'm having the user initiate authentication from a button in Discord. Looking at the source code, would y'all be OK if I added support for the discord state param containing a value for redirectTo? Perhaps JSON encoded?
How can I modify the source code of convex auth and test it out? When I change the node module it doesn't seem to have an effect.
Does this work in Clerk?6 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
I'm having trouble setting up convex auth for development in a way where convex sees my changes. Is there documentation on this?
The way I normally do this (for any npm package) is to clone the repo, make my changes, and then
npm pack
and run npm install path/to/packed_thing.tgz
in the project I'm testing with
For this repo in particular, I believe the test
and test-nextjs
subdirectories are set up to run against the version of Convex Auth in the repo
(you're totally right that we should document stuff like this for easier contribution / debugging)I managed to get it running like this:
In convex auth:
In another project:
I had to ensure they were both using the exact same version of convex because otherwise I ran into tons of typescript errors. And I have to
bun run build
convex auth each time I make a change for my other project to see it. Is there a way to get it to watch and build continuously?
Anyway, implementing this change is proving to be difficult because convex auth relies more on cookies than I expected. I can't rely on cookies if I'm initiating authentication from a button in discord.
I have a few options:
* Switch to Clerk. Maybe it will support discord authentication buttons without cookies?
* Link directly to my app and then initiate signIn automatically, redirecting to the Discord UI and using the cookie way of doing it. This is better if you're already signed in to discord in your browser, since it can bypass it entirely if you're already in, but in the case where you're not logged in or are logged in as the wrong user it's worse, since hitting the button in discord gets you most of the way there immediately.
* Modify Convex Auth to work even if the state is passed in from the state
parameter and not by consulting cookies.
Should the cookie-based state behavior still even exist? Is it better to replace it by always piping all the props through the state
param? I noticed that even if it is using cookies, it can use the state
param for something if you activate that in checks
...I thought the cookie stuff in convex auth was specifically for next.js middleware, which kind of needs it since it's all server there.
RE: watching and rebuilding, I do this:
It automatically rebuilds on a src/ change and renames the tarball to
convex-auth.tgz
for simplicity. I often run other projects on my own fork, and have them running a similar script for watching that tarball, copying, and installing. Works pretty great.