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)
7 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•3w 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•3w 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