TanStackT
TanStack4mo ago
4 replies
slow-yellow

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'
          )
        ),
      });
    }
  },
Was this page helpful?