amir
amir•7d ago

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?
No description
34 Replies
amir
amirOP•7d ago
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.
amir
amirOP•7d ago
yarn web from the root or yarn dev from the apps/next dir just FYI I am running npx convex dev in parallel too
erquhart
erquhart•7d ago
Welcome! 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)?
amir
amirOP•7d ago
You mean this?
export default {
providers: [
{
domain: process.env.CONVEX_SITE_URL,
applicationID: 'convex',
},
],
}
export default {
providers: [
{
domain: process.env.CONVEX_SITE_URL,
applicationID: 'convex',
},
],
}
CONVEX_SITE_URL is setup to convex instance in .env.local
erquhart
erquhart•7d ago
Where are you passing that url to the client
amir
amirOP•7d ago
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 project
erquhart
erquhart•7d ago
Set Up Convex Auth - Convex Auth
Authentication library for your Convex backend
amir
amirOP•7d ago
Ah yeah I have it
const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL!, {
verbose: true,
})
const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL!, {
verbose: true,
})
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
amir
amirOP•7d ago
No description
amir
amirOP•7d ago
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 error
amir
amirOP•7d ago
No description
erquhart
erquhart•7d ago
Ah I guess nextjs does send auth calls to the next site url
amir
amirOP•7d ago
Would you be able to run the repo I shared pls?
erquhart
erquhart•7d ago
Another thread with the same issue: https://discord.com/channels/1019350475847499849/1313937542835339414/1314049421423546368 Is your middleware logging working?
amir
amirOP•7d ago
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 18
erquhart
erquhart•7d ago
checking out the repo
erquhart
erquhart•7d ago
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.
erquhart
erquhart•7d ago
Might just be the config Yeah it's your config regex Yours:
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|public).*)'],
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|public).*)'],
Theirs:
matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
amir
amirOP•7d ago
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
erquhart
erquhart•7d ago
I would use the middleware from that repo as a reference, this all seems to originate from there
amir
amirOP•7d ago
Yes, I mean I just copied it, and only added await because was getting typescript error
amir
amirOP•7d ago
i can see the cookies added, but still isAuthenticated is false
No description
erquhart
erquhart•7d ago
Did you start this from a template convex directory should be split out from next nvm found it
erquhart
erquhart•7d ago
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
amir
amirOP•7d ago
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!
amir
amirOP•7d ago
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
"@auth/core": "^0.34.2",
"@convex-dev/auth": "^0.0.71",
"@auth/core": "^0.34.2",
"@convex-dev/auth": "^0.0.71",
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.
amir
amirOP•7d ago
So smth to check on the latest convex packages side I believe Thanks for the support sir ! @erquhart
erquhart
erquhart•7d ago
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
amir
amirOP•7d ago
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 helped
erquhart
erquhart•7d ago
Good to know, thanks for that
ballingt
ballingt•4d ago
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!
amir
amirOP•3d ago
awesome @ballingt , thanks. is it recommended to upgrade the version even if its working with the older one?
ballingt
ballingt•3d ago
Always recommended but not required, you could wait until there's a new feature you want. But before reporting a bug please update first.