Having Trouble with BetterAuth Middleware in Express and Next.js

0
10
Asked By CodingEnthusiast42 On

I've been struggling for days with my setup where I'm using Next.js for the frontend and Express with BetterAuth on the backend. My users are logged in successfully, and the requests work fine when I try them directly in the browser or through Postman. However, when I make the same requests using Axios or Fetch from my Next.js app, I keep running into issues. I'm getting a 400 status error from Axios, and my middleware seems to be causing the problem. I've shared links to the relevant parts of my code for both the backend and frontend. I've also checked that I've got CORS set up correctly, including credentials. I'm really stuck and would appreciate any help!

3 Answers

Answered By DevGuru88 On

It seems like you're missing some setup with cookies. You mentioned that you're using withCredentials: true, which is good, but make sure the login call is also being made with Axios to the correct URL. If cookies are created after login but not being sent with your requests, double-check the domain and path settings for your cookies, as they need to match your API requests. Also, ensure that your axios and CORS configurations allow cookies to be sent properly. Providing more context, like your login endpoint, may help too!

GavinNegron -

I’ll check the cookie settings again. Thanks for the tip!

Answered By FunnyDev29 On

Sounds like BetterAuth might not be so 'better' after all, huh? But seriously, check the headers being sent; it seems like cookies aren't making it to your backend during the requests. That's usually the culprit with middleware issues.

Answered By CodeMaster22 On

You might want to consider sharing a link to your entire repo so we can see how everything is structured. It's tough to debug when we only have partial code to look at.

GavinNegron -

Here's the link to my repo: https://github.com/GavinNegron/Blogging-Service

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.