Merdot
Merdot
SSolidJS
Created by Merdot on 1/9/2025 in #support
Throw redirects in data APIs with "use server" at the top of the file not working.
This is helpful, thanks for the answers!
5 replies
SSolidJS
Created by Merdot on 1/9/2025 in #support
Throw redirects in data APIs with "use server" at the top of the file not working.
I think I incorrectly explained it, I'll fix the initial post, I mean when I put the "use server"; at the top of the file, the redirect does not occur but when I put in in the function itself the redirect occurs. I notice that on the client, the /_server route is called with some headers that point to the wrapped function, but that call does not return a redirect but a 200. ie. Redirect works in SSR and on client interactions but bundle all my private function and it dependencies in the cliente, I don't want that code to land on the client.
// /lib/auth.ts

funtion authenticateService(request) {
// private function with authentication logic, not to be bundled.
// throw redirect may happen here.
}

funtion authenticateUser(request) {
// private function with authentication logic, not to be bundled.
// throw redirect may happen here.
}


export const getIdentity = query(async () => {
"use server"
// the query function gets wrapped in a server reference (RPC)
// call private functions
return value;
}, 'identity');
// /lib/auth.ts

funtion authenticateService(request) {
// private function with authentication logic, not to be bundled.
// throw redirect may happen here.
}

funtion authenticateUser(request) {
// private function with authentication logic, not to be bundled.
// throw redirect may happen here.
}


export const getIdentity = query(async () => {
"use server"
// the query function gets wrapped in a server reference (RPC)
// call private functions
return value;
}, 'identity');
Redirect do not work on SSR and client interaction call /_server and return a 200 no private code is bundled.
// /lib/auth.ts

"use server"

funtion authenticateService(request) {}

funtion authenticateUser(request) {}

// all exported function gets wrappep in a server reference
export const getIdentity = query(async () => {
// call private functions
return value;
}, 'identity');
// /lib/auth.ts

"use server"

funtion authenticateService(request) {}

funtion authenticateUser(request) {}

// all exported function gets wrappep in a server reference
export const getIdentity = query(async () => {
// call private functions
return value;
}, 'identity');
I imagine now that I think more of this, that because I'm marking the entire module as server, the query itself also is being executed in the server when is intended to occur on the client. How do I do redirect in code I want only to run on the server without bundling dependencies of that code to the client. If throw redirects in the route.load/preload functions the system just crash.
5 replies