T
TanStack•5mo ago
wise-white

Throwing redirect from server functions throwing an error in console and not redirecting

Hey folks, I'm using tanstack start + solidjs. I'm trying to throw a redirect from a server function and it's throwing an error on the console.
// src/lib/auth/actions
export const login = createServerFn().handler(async () => {
// ...
throw redirect({ href: "http://localhost:8787" })
})
// src/routes/index.tsx
//...
<button type="button" onClick={() => login()}>
Log in
</button>
// ...
// src/lib/auth/actions
export const login = createServerFn().handler(async () => {
// ...
throw redirect({ href: "http://localhost:8787" })
})
// src/routes/index.tsx
//...
<button type="button" onClick={() => login()}>
Log in
</button>
// ...
Let me know if I'm doing something silly, otherwise I can try creating a minimal reproduction repo. Thanks for the help in advance 🫶
No description
3 Replies
wise-white
wise-white•5mo ago
you need useServerFn
wise-white
wise-white•5mo ago
Server Functions | TanStack Start Solid Docs
What are Server Functions? Server functions allow you to specify logic that can be invoked almost anywhere (even the client), but run only on the server. In fact, they are not so different from an API...
wise-white
wise-whiteOP•5mo ago
I knew I was missing something 😂 Yep that worked 🫶 thanks 🫶

Did you find this page helpful?