Redirect to current location from createServerAction$()

I have a logout action that I would like to logout the user without changing the location. My current code looks like this:
const [, logOut] = createServerAction$(async (_, { request }) => {
const session = await storage.getSession(request.headers.get('Cookie'));
return redirect('/', {
headers: {
'Set-Cookie': await storage.destroySession(session),
},
});
});
const [, logOut] = createServerAction$(async (_, { request }) => {
const session = await storage.getSession(request.headers.get('Cookie'));
return redirect('/', {
headers: {
'Set-Cookie': await storage.destroySession(session),
},
});
});
This code is functional but it redirects to the home page of my app. I can't use useLocation() in a server action, so is there a way to do this without redirecting to the home page?
3 Replies
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
jesseb34r
jesseb34r15mo ago
how would I 'send the current location in the action'?
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server
More Posts