ERROR api/auth/sign-in-social

Hi everyone, I am beginner with better-auth. I do setup a Auth with my project but i got error 404 not found. Is there some tip for fix this issue?
No description
7 Replies
birthdaycake7360
birthdaycake7360OP2w ago
There is my auth, auth-client.ts and route.ts
No description
No description
No description
No description
birthdaycake7360
birthdaycake7360OP2w ago
I using Vite
Jacob
Jacob2w ago
are you using vite? or nextjs?
birthdaycake7360
birthdaycake7360OP2w ago
I am using Vite
Jacob
Jacob2w ago
Alright assuming you would also have a backend client if you have a frontend client. this is how it should be setup. the auth handler lives on the server whether this is using a fullstack framework e.g Nextjs, Tanstack, Remix, etc (with api routes) or using a backend service like Hono, Express, etc. this is because it interacts with the database and other sensitive information that shouldn't be on the client while the authClient (as in the name) lives on the client in this example your vite app. vite by itself (i believe) doesn't support api routes / server rendering unless using a framework / package to handle this. the toNextjsHandler() is for nextjs while it might work depending on the setup, what you need to do is mount the handler to be something like this:
const GET = (request: Request) => {
return auth.handler(request)
}

const POST = (request: Request) => {
return auth.handler(request)
}
const GET = (request: Request) => {
return auth.handler(request)
}

const POST = (request: Request) => {
return auth.handler(request)
}
but this is all dependent on your framework and how it defines api routes
birthdaycake7360
birthdaycake7360OP2w ago
Hi @Jacob , did you have some example with Vite project ( My project Flask Backend, Frontend: Vite react)
Jacob
Jacob2w ago
I don’t quite have an example for you but I would recommend using either https://reactrouter.com/ (firmly remix) or https://tanstack.com/start/latest (have found this hard to deploy but others seem to have been having an amazing time with it) other of which have examples in the better auth docs . Since its mostly a client side app the frameworks job is to mainly handle the api route and than you just run your react code the same way
TanStack Start
Full-document SSR, Streaming, Server Functions, bundling and more, powered by TanStack Router and Vite - Ready to deploy to your favorite hosting provider.

Did you find this page helpful?