Server show signed in & refreshed token, yet, <Unauthenticated> is triggered
What am I missing here? I'm just trying to use Email/Password Signup & Register. Nothing else. Not using OAuth.
Been working fine for months with Clerk. I am trying to migrate to Convex Auth. The project is huge so i did screen shots and compressed the user functions (partial) and user schema into a single TS file. The server is configured, tables, env, keys.
It looks like its working but there is some disconnected with the Provider/Context?
16 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!
No guesses? Try support?
A couple weird things in the set up that may or may not be related to what you're seeing:
* What's
NEXT_PUBLIC_CLERK_DOMAIN
? Is it just an old variable name that is actually set to be your .convex.site
URL like Convex Auth requires?
* The getAccessToken
function in the auth.ts
seems wrong -- that's not returning an access token, it's returning a token identifier which is different.
What's the page that's showing "Not Authenticated"? Is it server rendered or client rendered? Is this just going off of useConvexAuth
/ isAuthenticatedNextjs
, or something more sophisticated?
I'd also suggest temporarily enabling verbose logging to get more insight into what exactly might be happening here (https://labs.convex.dev/auth/debugging#enabling-verbose-logging)Debugging - Convex Auth
Authentication library for your Convex backend
1. NEXT_PUBLIC_CLERK_DOMAIN is left over from converting. CLERK removed
2. "Not Authenticated" is the landing page for Messenger. Auth Route. I converted it and was testinging the <Authenticated> <Unauthenticated> <AuthLoading> etc before I convert the rest. Very big app.
I have been in Convex Auth Docs for days. I have this working on 3 other sites, but its the basic. For this App I am trying to Auth Server Side, but expose the User data to the page/components clients side.
So, I need the User and info from Admin and Subscription tables to be available. The others do not do that yet. they are basic
at this time i have it all broke because i tried going back to the basics to see if i could get this to work correctly.
now i have an absolute mess 😦
i guess i should just create a function to lookup and return what i need and call it from the components?
Can you try some logging in your custom auth provider to see if authentication state is ever being properly captured client side?
App size aside, this looks like it should still be a pretty straightforward nextjs integration for auth.
yeah. give me a few. ill have to create another branch and reimplement.
@erquhart re: "authentication state is ever being properly captured client side?" altualy its not. isAuthenticated is false
wow. i am stumped. Here is the latest.
logs, relevant files...
user.ts:getCurrentUser()
oh, debug func (doubt you need it)
Failed to authenticate: "No auth provider found matching the given token", check your server auth config
is buried in your logs.
Follow the step here to check that the JWT you have in your cookies matches up with the auth providers configured for your deployment
(I'm about to make a more interactive way of testing this out)Debugging Authentication | Convex Developer Hub
You have followed one of our authentication guides but something is not working.
@sshader
@sshader hmmm - actually you are correct. I compared to repo last commit
NEXT_PUBLIC_CLERK_DOMAIN
not CONVEX_SITE_URL
and i did not have my npx convex dev
running in second terminal as i usually do.
after running that it worked and kept redirecting. Did dome rewrite on middleware and now it is working.
Let me work out all the kinks and clean up the code and I'll create a working example for everyone.
@sshader @erquhart Thank you for helpGlad it's working! So you needed to switch the clerk variable for the convex site variable right? For the dev process, I very much recommend having a single command for local dev that runs your client and convex together for this reason. The false positives in your first image definitely didn't help the process, though, wonder how anything had an authenticated state server time if the domain variable was wrong.
yes. well, i had switched it but did not update convex (
npx convex dev
) was not running in seperating terminal - so it did not update
if any lesson for this right off the top of my head for others is ALWAYS make sure you have npx convex dev
running in a separate terminal...even if you think you will not make changes to that. That way your used to it syncing automatically...and you wont waste 1.5 days 🙂
so now, i need to convert this HUGE app over this week, then QA. When done i'll post it to Show and Tell
- 100% NextJS/Convex+Authnpx convex dev
is love, npx convex dev
is lifeI just use concurrently and run the dev server and convex running at the same time
i do too. i stopped it instad of npm run dev to install / remove a package and never restarted it lol