Convex Auth + Tamagui (Monorepo)
Hey, I added convex to my nextjs app so far, but trying to use Auth
signIn
Im getting http://localhost:3000/api/auth
404 Not found error. What am I doing wrong?34 Replies
Here is the repo for reproduction: https://github.com/emrme/tamagui-convex
GitHub
GitHub - emrme/tamagui-convex
Contribute to emrme/tamagui-convex development by creating an account on GitHub.
yarn web
from the root or yarn dev
from the apps/next dir
just FYI I am running npx convex dev
in parallel tooWelcome! it shouldn't be localhost, it should be the url to your convex instance. Where are you providing the convex url to your client(s)?
You mean this?
CONVEX_SITE_URL
is setup to convex instance in .env.local
Where are you passing that url to the client
Smth is odd, nor sure what exactly tho 🙂 but just FYI:
If I import provider from
import { ConvexAuthProvider } from '@convex-dev/auth/react'
instead of
import { ConvexAuthNextjsProvider } from '@convex-dev/auth/nextjs'
Im not getting that error!
But then the auth is not working because this is nextjs app
Just tried to search for that string CONVEX_SITE_URL
I am not passing it anywhere, only used inside the auth.config.ts
, also I was just following the official guide on how to add Convex Auth to an existing projectHere’s the step: https://labs.convex.dev/auth/setup#set-up-the-react-provider
Set Up Convex Auth - Convex Auth
Authentication library for your Convex backend
Ah yeah I have it
CONVEX_SITE_URL=localhost:3000
It was set on the convex backend side I believe while doing
npx @convex-dev/auth
But the NEXT_PUBLIC_CONVEX_URL
is set to https://next-rook-766.convex.cloud
I think I gotcha! You mean I have to do
npx @convex-dev/auth
again and set the SITE_URL to my convex instance url, right?
Changed, but still getting that same errorAh I guess nextjs does send auth calls to the next site url
Would you be able to run the repo I shared pls?
Another thread with the same issue: https://discord.com/channels/1019350475847499849/1313937542835339414/1314049421423546368
Is your middleware logging working?
Yep
Also im not using
src
directory, was using initially but since getting these errors, thought that might be thee cause and moved everything to the root of nextjs app directory
Also Im on react 18checking out the repo
When I use the middleware from the next/convex auth template it works: https://github.com/get-convex/template-nextjs-convexauth-shadcn/blob/main/middleware.ts
GitHub
template-nextjs-convexauth-shadcn/middleware.ts at main · get-conve...
Convex + Next.js + Convex Auth. Contribute to get-convex/template-nextjs-convexauth-shadcn development by creating an account on GitHub.
Might just be the config
Yeah it's your config regex
Yours:
Theirs:
Just changed the middleware, did it work for you?
Also pushed to the repo, can you check pls if its the same as yours?
added
await
to convexAuth.isAuthenticated()
And for some reason its always returning false
to me
But the signin with google flow triggered -- yes
However after signin in Im landing again on the login
page and getting false
for isAuthenticated
I would use the middleware from that repo as a reference, this all seems to originate from there
Yes, I mean I just copied it, and only added
await
because was getting typescript errorGitHub
tamagui-convex/apps/next/middleware.ts at master · emrme/tamagui-co...
Contribute to emrme/tamagui-convex development by creating an account on GitHub.
i can see the cookies added, but still
isAuthenticated
is falseDid you start this from a template
convex directory should be split out from next
nvm found it
This template uses Clerk instead of Convex Auth, so you'll need to swap that part, but I would use it as a reference on how to integrate Convex into your turborepo app: https://github.com/get-convex/turbo-expo-nextjs-clerk-convex-monorepo
GitHub
GitHub - get-convex/turbo-expo-nextjs-clerk-convex-monorepo: Monore...
Monorepo template with Turborepo, Next.js, Expo, Clerk, Convex - get-convex/turbo-expo-nextjs-clerk-convex-monorepo
i dont think this is the issue with monorepo setup tbh, as the sign in triggered and the cookies are set, also inside db i can see the entries
But inside middleware
isAuthenticated
is still false
Might be version issues or smth
Yes exactly!Downgraded version to the ones used in this template https://github.com/get-convex/template-nextjs-convexauth-shadcn/blob/main/middleware.ts
and now its working
GitHub
template-nextjs-convexauth-shadcn/middleware.ts at main · get-conve...
Convex + Next.js + Convex Auth. Contribute to get-convex/template-nextjs-convexauth-shadcn development by creating an account on GitHub.
So smth to check on the latest convex packages side I believe
Thanks for the support sir ! @erquhart
Interesting, downgrading shouldn't be required
But hey, glad you're unblocked
I was getting strange convex api import errors in addition to the auth issues locally, hence the recommendation to standardize your setup
yeah will get to that, just needed to make sure it works first 🙂
also just double checked with latest package versions,
isAuthenticated
is being returned as false again in the middleware, downgrading helpedGood to know, thanks for that
The behavior of
isAuthenticated
changed in the last release, now it involves a call to the Convex backend to check that the token really is valid.
I can't access the repo, @amir I'd love to take a look. We'll be updating these examples so if there's a problem that also comes up in those it'll be addressed, but something about your setup could be different.
@amir I added migration instructions here https://github.com/get-convex/convex-auth/blob/main/CHANGELOG.md, you need to add isAuthenticated
to convex/auth.ts. Sorry for the forgotten instructions!awesome @ballingt , thanks. is it recommended to upgrade the version even if its working with the older one?
Always recommended but not required, you could wait until there's a new feature you want. But before reporting a bug please update first.