T
TanStack•2mo ago
extended-salmon

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
sensitive-blue
sensitive-blue•2mo ago
you need useServerFn
sensitive-blue
sensitive-blue•2mo 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...
extended-salmon
extended-salmonOP•2mo ago
I knew I was missing something 😂 Yep that worked 🫶 thanks 🫶

Did you find this page helpful?