SolidJSS
SolidJSβ€’12mo ago
Merdot

Throw redirects in data APIs with "use server" at the top of the file not working.

Hi everyone! πŸ‘‹

I'm working on a Solid Start project and have a question about query behavior and redirects.

I have a query called getIdentity, which fetches user identity from cookies and db. The goal is to call this query on the /account page to check the user's identity. If no identity is found, I throw a redirect to /signin.

Here's the issue:

When I use "use server" in the query, the redirects work perfectly.
However, when I try to move the "use server"; to the top of the file (to prevent the identity-fetching logic from being bundled to the client), the redirects stop working.
I’d like to keep this logic at the top of the file, but I can’t figure out how to ensure the redirect still works.

Any ideas on how to handle this better? Is there a recommended pattern for managing such server-only logic and redirects in Solid Start?

Thanks in advance for your help! πŸ™
Was this page helpful?