Behrooz Evans
Behrooz Evans•2mo ago

hey champs, I configured my app with

hey champs, I configured my app with convex auth and integrated it with the auth docs (added github model), but when I use the github sign in button it throws 404 /api/auth POST any clue why?
75 Replies
Sara
Sara•5w ago
This is because you need to add the middleware that does the API calls for next,hs at least
Behrooz Evans
Behrooz EvansOP•5w ago
Yeah I did
Sara
Sara•5w ago
can you show me your middleware?
Behrooz Evans
Behrooz EvansOP•5w ago
Sure
Sara
Sara•5w ago
usually people play with the matcher and it doesn't work properly afterwards + where you placed your middleware.ts
Behrooz Evans
Behrooz EvansOP•5w ago
No description
Behrooz Evans
Behrooz EvansOP•5w ago
import { convexAuthNextjsMiddleware, createRouteMatcher, nextjsMiddlewareRedirect, } from "@convex-dev/auth/nextjs/server"; const isSignInPage = createRouteMatcher(["/signin"]); const isProtectedRoute = createRouteMatcher(["/product(.*)"]); export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => { if (isSignInPage(request) && (await convexAuth.isAuthenticated())) { return nextjsMiddlewareRedirect(request, "/dashboard"); } if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) { return nextjsMiddlewareRedirect(request, "/password"); } }); export const config = { // The following matcher runs middleware on all routes except static assets. matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"], }; there has to be something wrong with middleware @Sara
Sara
Sara•5w ago
You don't have /product nor /signin 😅
Behrooz Evans
Behrooz EvansOP•5w ago
I replaced it now its the same again
Sara
Sara•5w ago
The matcher is correct and the placement of the middleware is correct
Behrooz Evans
Behrooz EvansOP•5w ago
import { convexAuthNextjsMiddleware, createRouteMatcher, nextjsMiddlewareRedirect, } from "@convex-dev/auth/nextjs/server"; const isSignInPage = createRouteMatcher(["/auth"]); const isProtectedRoute = createRouteMatcher(["/dashboard(.*)"]); export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => { if (isSignInPage(request) && (await convexAuth.isAuthenticated())) { return nextjsMiddlewareRedirect(request, "/dashboard"); } if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) { return nextjsMiddlewareRedirect(request, "/auth"); } }); export const config = { // The following matcher runs middleware on all routes except static assets. matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"], }; here no product no sign in yet we face 404
Behrooz Evans
Behrooz EvansOP•5w ago
No description
Sara
Sara•5w ago
Oh! Could it be how you imported the layout?
Behrooz Evans
Behrooz EvansOP•5w ago
I can give repo link if that helps (btw thank you for helping) like how
Sara
Sara•5w ago
Can you share a screenshot of your layout please
Behrooz Evans
Behrooz EvansOP•5w ago
definitely
Sara
Sara•5w ago
You're supposed to pass the server auth component in your layout for all this to work
Behrooz Evans
Behrooz EvansOP•5w ago
GitHub
GitHub - muperdev/collabute at dev
Collabute Website. Contribute to muperdev/collabute development by creating an account on GitHub.
Behrooz Evans
Behrooz EvansOP•5w ago
well I did
Behrooz Evans
Behrooz EvansOP•5w ago
sign in page is /auth and I passed client component to it as well since its a client componennt
Sara
Sara•5w ago
I don't see your client side provider 😅 Where did you import it?
Behrooz Evans
Behrooz EvansOP•5w ago
its wrapped around the auth page
Sara
Sara•5w ago
Give me a moment to clone the repo real quick
Behrooz Evans
Behrooz EvansOP•5w ago
here sure sorry to bother you
Sara
Sara•5w ago
is it the dev braanch?
Behrooz Evans
Behrooz EvansOP•5w ago
yep
Sara
Sara•5w ago
Are you migrating an existing project to convex? or is there a reason why you're using next's node backend + convex?
Behrooz Evans
Behrooz EvansOP•5w ago
yeah this is an existing project Im moving away from my backend to convex so here we have new schemas, convex mutations and functions and also auth is the last bottle neck there are some api routes Im using for AI purposes
Sara
Sara•5w ago
I'm getting error 500 On everything almost, so I'll make the test on one of my pre existing projects just use convex 😅
Behrooz Evans
Behrooz EvansOP•5w ago
for AI ones?
Sara
Sara•5w ago
yes
Behrooz Evans
Behrooz EvansOP•5w ago
that would be down the line but is it a blocker?
Sara
Sara•5w ago
they have the Agent component which is insanely good it is not, just a suggestion :))
Behrooz Evans
Behrooz EvansOP•5w ago
I still didn't opened that doc page, have to do it one day or another defo probably will do it before launch but lets see
Sara
Sara•5w ago
Well, on my side
Behrooz Evans
Behrooz EvansOP•5w ago
yeah
Sara
Sara•5w ago
I'm not even hitting the /auth or /api what so ever
Behrooz Evans
Behrooz EvansOP•5w ago
really?
Behrooz Evans
Behrooz EvansOP•5w ago
No description
Behrooz Evans
Behrooz EvansOP•5w ago
this button of mine is connected to convex sign in
Sara
Sara•5w ago
cc: @ballingt I think what you might need to do is name the api route something else like say _api temporarily, and test it out from there, to me everything seems right and in order, so I'm so sorry I can't be of help from here 😅
Behrooz Evans
Behrooz EvansOP•5w ago
no worries thank you for suggestions I will go down that route
erquhart
erquhart•5w ago
I can help reading through
Behrooz Evans
Behrooz EvansOP•5w ago
thank you I was into the betterauth thing but that was overhead for me so was trying to checkout the normal convex auth @erquhart
erquhart
erquhart•5w ago
Yeah convex auth should work well
Sara
Sara•5w ago
+ one suggestion is to move the client Provider to the Layout. since it has to be wrapped in all the pages, not just the auth
Behrooz Evans
Behrooz EvansOP•5w ago
let me try that sara no same... ooof
erquhart
erquhart•5w ago
Are the 404's logging in your Convex dashboard or just in next
Behrooz Evans
Behrooz EvansOP•5w ago
in next
erquhart
erquhart•5w ago
and you're seeing the 404 in your network panel in the browser or is this happening server side
Behrooz Evans
Behrooz EvansOP•5w ago
yeah is a client side request
erquhart
erquhart•5w ago
what's the url that's getting the 404
Behrooz Evans
Behrooz EvansOP•5w ago
No description
Behrooz Evans
Behrooz EvansOP•5w ago
No description
Behrooz Evans
Behrooz EvansOP•5w ago
its the localhost/api/auth
erquhart
erquhart•5w ago
that seems like a holdover from trying better auth taking another look at convex auth docs, trying to remember what proxying is happening there
Behrooz Evans
Behrooz EvansOP•5w ago
thanks that would be great
erquhart
erquhart•5w ago
What does it look like when you're calling sign in? Import / function call
Behrooz Evans
Behrooz EvansOP•5w ago
convex sign in? never tried it yet
erquhart
erquhart•5w ago
The function call that is producing this network request
Behrooz Evans
Behrooz EvansOP•5w ago
ah that one
Behrooz Evans
Behrooz EvansOP•5w ago
here
Sara
Sara•5w ago
@Behrooz Evans I found the problem
Behrooz Evans
Behrooz EvansOP•5w ago
yoho there we go
Sara
Sara•5w ago
move the middleware out of the app, into the root
Behrooz Evans
Behrooz EvansOP•5w ago
ah
Sara
Sara•5w ago
I always mistake them when using src haha
Behrooz Evans
Behrooz EvansOP•5w ago
tada worked
Sara
Sara•5w ago
hope that works
Behrooz Evans
Behrooz EvansOP•5w ago
bullseye sara yeah that was the cause same here great thanks everyone will bug you a lot for infinite and I know I always have you on back have a good day :))
erquhart
erquhart•5w ago
awesome catch Sara!

Did you find this page helpful?