React Router v7 Integration
I want to add auth in react router v7 app, the better-auth docs only mention the integration for Remix, so i tried using that but it didnt work
im new to react router / remix and dont know how to make it work
the below method mentioned in remix integration docs gives 405 error on form submission
// POST http://localhost:5173/api/auth/sign-up/email 405 (Method Not Allowed)
8 Replies
so i tried using the
action
function, which also didn't work
// POST http://localhost:5173/auth/register.data 400 (Bad Request)
im not sure im doing it right or wrongWhats your auth.ts look like and where have you implemented your handler?
>app/lib/auth.ts
>app/routes/api.auth.$.ts
>app/lib/auth-client.ts
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
this works but not as expected,
its signing up the user if i use the onSubmit in the page itself (the nextjs way), ideally it should work with the action function, which it does not
also, after the user is signed up, and i try to log in using the same methodology as signup, the "page" shows "Error - Method not allowed", with empty console logs, but the onSuccess method gets triggered and i get the alert of "sign up successful", but then session is null in the app, but in the cookies i can see the
better-auth.session_token
okay now im not getting the method not allowed error but its still not signing me in
this is how im doing it
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
Thanks Phillex, this worked, ill keep that in mind,
Also, for anyone new, react-router framework specific docs will be appreciated
Hi, I have a problem with the react router 7 framework mode + cloudflare when trying to set up second storage. So I am using the RR7 cloudflare template and it allows you to access all of the bindings through a prop passed to the loader and action. However, this prop is only available in those context. With betterAuth, we need to create a betterAuth instance isolated. I have no idea how to set up the second storage with this set up. Any idea?
My work around is to define 3 different api routes for get, set, delete then make a fetch call to them. and in those route, i will have access to the cloudflare binding and then do some stuff with kv. This doesn't sound right to me.