T
TanStack8mo ago
correct-apricot

Routing issues with better-auth

I've built a TanStack Start app based on better-auth's example and struggling with two issues: 1. something navigates to /auth/signin? (the '?' is actually tacked on) when better-auth's signin runs. I don't know what is doing the navigation nor why it appends a '?'. 2. TanStack's navigation doesn't work inside better-auth's signin onSuccess callback. I've tried router.navigate and useNavigation with and without router.invalidate() and router.invalidate({sync: true}) The call to better-auth's signin function looks like this:
const {data, error
} = await signIn.email(
{email, password},
{
onRequest: async (ctx) => {
},
onSuccess: async (ctx) => {
router.navigate({to: '/'})
},
onError: (ctx) => {
console.error({ctxError: ctx.error.message})
},
},
)
const {data, error
} = await signIn.email(
{email, password},
{
onRequest: async (ctx) => {
},
onSuccess: async (ctx) => {
router.navigate({to: '/'})
},
onError: (ctx) => {
console.error({ctxError: ctx.error.message})
},
},
)
So, three questions: 1. What might be causing an unwanted navigation from /auth/signin to /auth/signin? and how might I stop it? 2. What might want to append a '?' to the url. What does it mean? Is it a clue? 3. How might I get navigation working in the signin success callback? Note the callbacks run on the client. Re question 1., I've confirmed that none of my code nor TanStack router's config explicitly checks for authentication nor automatically routes to /auth/signin?. I don't believe better-auth is routing either but can't rule that out for sure. Note I see a log message saying Navigated to http://localhost:3000/auth/signin? but no indication of who generated the log message. Does that log message look familiar? TanStackRouterDevtools gives the 'cause' of the navigation as 'enter'. Is that a clue? It doesn't show the mysterious '?' in the recorded route. I can jerry-rig the desired navigation to '/' with window.location.href = '/' in onSuccess or with TanStack routing in useEffect. Neither seem ideal and the latter exhibits the mysterious navigation to /auth/signin?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?