Rodrigo-R
Rodrigo-R•6mo ago

Convex Auth... Authenticated works but auth.getUserId(ctx) returns null

Hi! Quick question (hopefully) my auth cycle is working, i can use
<Unauthenticated>
...
</Unauthenticated>
<Authenticated>
...
</Authenticated>
<Unauthenticated>
...
</Unauthenticated>
<Authenticated>
...
</Authenticated>
And it's working as expected, but on the convex side i get null when i ask to the auth user. any tips on where to start looking? Thank you for your help!
8 Replies
ian
ian•6mo ago
is it consistently or only occasionally? there's a general auth debugging guide that can be helpful: https://docs.convex.dev/auth/debug
Debugging Authentication | Convex Developer Hub
You have followed one of our authentication guides but something is not working.
Rodrigo-R
Rodrigo-ROP•6mo ago
it is consistently, i'll follow the guide and report back!
Michal Srb
Michal Srb•6mo ago
(usually it's because your function is not actually inside a component that's wrapped in Authenticated, and so it runs too soon)
ian
ian•6mo ago
Or b/c you don't have it listed as a provider in auth.config.ts - though then it wouldn't render in <Authenticated>
Rodrigo-R
Rodrigo-ROP•5mo ago
thanks i'll look into it now (busy day) I have the ConvexClient (with auth) in my root layout and my auth.config.ts untouched
export default {
providers: [
{
domain: process.env.CONVEX_SITE_URL,
applicationID: "convex",
},
],
};
export default {
providers: [
{
domain: process.env.CONVEX_SITE_URL,
applicationID: "convex",
},
],
};
i'm sure i broke something, but i can't find out what :S After long hours, It seems NextJs is not supported yet, that may be the cause?
Michal Srb
Michal Srb•5mo ago
Server-side authentication with Next.js is not supported yet. Are you using preloadQuery or fetchQuery?
Rodrigo-R
Rodrigo-ROP•5mo ago
yup, but i couldn't find how to get the token, the docs only describe clerk and auth0 😦
Michal Srb
Michal Srb•5mo ago
We're working on it, hang tight

Did you find this page helpful?