Getting so many errors related to mongo db
I'm trying to use better auth in nextjs
I'm currently learning so most probably my mistake but what can someone please explain I'm using mongo db adapter and email password
It is a test project to learn better auth before implementing on main project
For database mongo db atlas
I'm using google idx as ide right now I only have android devices
Tech stack,- next js tailwind react vanilla javascript






19 Replies
Why are you fetching the api with axios
API | Better Auth
Better Auth API.
This is the correct way to call an endpoint server side
The console errors is you are trying to call the mongodb in a client component aka in the browser environment
Because I don't know and chat gpt instructed and blindly followed
Thanks I would give it try let you know
And you can't
I recommend have a solid look at the docs and also chatgpt wont know what to do as it probably wont have knowledge on it yet
Then I should only call mongo db in server
What is your page for login
the page.jsx
Its just have form that for better auth signup with email I was testing the better auth
yeah but your calling your having errors inside of your page file to help you it would be great to have the full context
One more thing I don't know how to code yet so I would read docs
Just try bunch of things and if doesn't work follow a youtube tutorial
Sure wait a little
Are you confident that you implement all of these technologies together?
Well I couldn't understand fully
I'm not confident
But will make it work it's my determination
Im making saas platform
So I need to learn these technologies
And my method (try and try again )may be inefficient but I like it
I first took help of youtube
Then llms then I'm here



I had gemni generate a form I was planning to Edit it but I get so many errors I didn't know what to do
If you're using the next middleware, it's completely fine to use axios.
You can't use the better-auth instance in middleware since Next middleware doesn't support Node (yet)
In saying that, it's also possible that axios doesn't work in middleware too.
I would recommend you move your middleware verification logic to check at a per-page level, instead of in the middleware.
It's still fine to do this, I just wouldn't recommend it.
If you want to continue using middleware, then I recommend you look into better-fetch and utilize better-fetch to fetch your session using that same route, instead of using axios since I can't verify if that works or not.
I will remove the middleware completely and implement per page logic
Since I don't want to add one more complex piece of puzzle to it
And thank you
Make sure to run authentication on a server component to ensure the user is allowed to view that page.
If they are not allowed, use Next.js built-in functionallity to redirect users away. (eg
NotFound()
)
You can get the users session like so:
make sure to import headers
from next/headers
.I will try and surely update you