T
TanStack2d ago
sunny-green

Remove search params from url on beforeLoad

What is the preferred way of deleting search params from the URL? We have implemented a magic link auth system that basically adds the JWT token to the URL, I set this JWT token in localstorage and it handle by the API. But i dont want this token to be in the URL the whole time so i want to delete it as soon as its added to localstorage.
beforeLoad: async ({ context, search }) => {
if (search.access_token && search.refresh_token) {
setTokens({ data: { access_token: search.access_token, refresh_token: search.refresh_token } });
// This feels really wrong, its not a redirect
throw redirect({
search: Object.fromEntries(
Object.entries(search).filter(
([key]) => key !== 'access_token' && key !== 'refresh_token'
)
),
});
}
},
beforeLoad: async ({ context, search }) => {
if (search.access_token && search.refresh_token) {
setTokens({ data: { access_token: search.access_token, refresh_token: search.refresh_token } });
// This feels really wrong, its not a redirect
throw redirect({
search: Object.fromEntries(
Object.entries(search).filter(
([key]) => key !== 'access_token' && key !== 'refresh_token'
)
),
});
}
},
3 Replies
rising-crimson
rising-crimson2d ago
why is it not a redirect? removing it from search means navigating to a different url
sunny-green
sunny-greenOP2d ago
So what I’m doing is correct?
rising-crimson
rising-crimson2d ago
i dont see an issue with this

Did you find this page helpful?