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?
4 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
jesseb34r
jesseb34rOP2y ago
how would I 'send the current location in the action'?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
AlexErrant
AlexErrant2y ago
you can put it in a query param or a hidden form field
Want results from more Discord servers?
Add your server