Auth don't work with Next js and ConvexAuthNextjsProvider
I'm having issues with getting auth to work with the ConvexAuthNextjsProvider. All iss setup as described in https://labs.convex.dev/auth/authz/nextjs.
In the middleware.ts it seems to be working as expected (isAuthenticated is true).
But when i do
export const checkout = action({ args: { plan: v.string() }, handler: async ({ auth }, { plan }) => { console.log('server identity', await auth.getUserIdentity()) }, }) It just return
await fetchAction(api.stripe.checkout, { plan: 'starter' })
andexport const checkout = action({ args: { plan: v.string() }, handler: async ({ auth }, { plan }) => { console.log('server identity', await auth.getUserIdentity()) }, }) It just return
null
(on a clickhandler insiden react)..
I have gone trought the debugging section in the docs (https://docs.convex.dev/auth/debug)
Everything looks good, except that in the header, i don't get typ: "JWT"
, only "alg": "RS256"
Can you point me in the right direction?Debugging Authentication | Convex Developer Hub
Troubleshoot authentication issues in Convex



46 Replies
I'm using Oauth with google
ello there,
for serverside to work, you need to pass the auth token in your Action/Query/Mutation
Server-side authentication in Next.js - Convex Auth
Authentication library for your Convex backend
(to work for functions that require auth!)
also, I prefer using the function
its just a personal preference since it already does the identity check
The component itself uses 'use client'

I still need to do that?
you don't need to use use client no
but if you want you can pass "use server" at the top of the function defention
No, i mean, i want to use "use client". Then sending token is not necessary?
if you want it to be client, use
useAction
/ useQuery
oh hold onHm, so i need to use useAction, even if its inside a click handler?
move the query out of the button
let's do this from the start, shall we?
That seems to work
Amazing haha
So i can't use fetchQuery directly inside a handler?
no, because Queries are supposed to be used to fetchData, not to update them
I mean actions
you can!
Or any of them really
you just use useAction or fetchAction depending on what you really need
So why didn't my first example work?
because you were using fetchQuery..
This don't work

Then the user is
null
Again, this is because you didn't pass the token in the action
:ahhh:
But its on the client
So fetchAction on the client don't work?
This is what I'm saying
fetchAction is for server side
Do you understand the difference, I can explain it if you want
Yeah, i think so π
@Sara Thank you, seems to be working.
Another question i have when using Next, is the use of http.ts. Will tht work with the use of Next? I'm trying to get stripe callbacks to work, but it seems like when i follow the template (https://www.convex.dev/templates/stripe), /stripe is never acceccable (probably because its a Next route)?
so when it comes to HTTP, you're not calling the api from Next, you'd be using the
.site
url from convex`stripe listen --forward-to https://localhost:3000/stripe``
So this needs to be .site url, not localhost?
no that seems to be correct
if you want to do a http fetch request, you'd need to use the convex url
I'm reading the Repo now
I'm talking about the callback that recives stripe events
http.route({
path: '/stripe',
method: 'POST',
handler: httpAction(async (ctx, request) => {
const signature: string = request.headers.get('stripe-signature') as string
const result = await ctx.runAction(internal.stripe.webhook, {
signature,
payload: await request.text(),
})
if (result.success) {
return new Response(null, {
status: 200,
})
} else {
return new Response('Webhook Error', {
status: 400,
})
}
}),
})
When i go to localhost:3000/stripe i get to a 404, because it don't exist in Next
Yep this acts as an API request
do you have a folder directory for stripe page?
So i need to do the stripe callback in the route.ts (in next), and do api calls for each event?
I can crete a /stripe route in Next, and then do api calls to convex, but was hoping i didn't need the next route
mmm I need some time to read the repo, I'm also not experienced with stripe
so I can answer the questions
I'm pretty sure that the http.route /stripe is soemthign that stripe hits when doing callbacks
As a webhook
you could try that
I did try it, but as i said its not hit, because /stripe is served by next, not convex
the route would be the url from convex, remove .cloud and replace it with .site
stripe listen --forward-to **.site
I'll tryt hisit seems we were wrong
https://stack.convex.dev/stripe-with-convex
I'm reading this right now, you should keep the hosting url
Wake up, you need to make money! (Add Stripe to your product)
If youβre building a full-stack app, chances are youβll want some of your users to pay you for the service you provide. How to use Stripe with Convex ...
It worked with what i suggested above, to use the .site as forward-to
Thanks
Really! damn
I tried with localhost again now, and it actually seems that that also worked now π
Not sure what i did wrong earlier
that's pretty interesting
good job
Anyways, thanks