https://supabase.com/ logo
#javascript
Title
# javascript
m

Mac

01/07/2022, 8:04 PM
Hey peeps! I've been wondering why the Supabase Auth client (or perhaps the GoTrue client used under the hood) doesn't clear the auth data hash upon a successful redirect to a "non-standard" URL, ie. one that doesn't match the default URL's root route. In other words, if I set
redirectTo
to
http://localhost:3000/foobar
, upon successful auth I will be taken to
http://localhost:3000/foobar#access_token=123abc&expires_in=3600&you_get=the_idea
, and that's it, hash will stay there.
My code could be at fault here, so I'll describe how I set up a
redirectTo
option for
signIn
as well as a workaround I've come up with
Just before that, I'm using Vue.js version
3.2.16
with Vue Router version
4.0.11
and Supabase client version
1.29.1
Here's how I create a redirect URL and pass it to Supabase's `auth.signIn`:
Copy code
ts
const redirectPath = route.query.redirect as string;
const redirectTo = `${window.location.origin}${redirectPath || '/'}`;
const { error } = await supabase.auth.signIn({ provider }, { redirectTo });
And it does successfully redirect me to that desired address, but as I said, the auth data hash does not get cleared by Supabase/GoTrue client
I've managed to work around this issue by creating a custom
afterEach
guard for my router:
Copy code
ts
import { NavigationFailure, RouteLocationNormalized } from 'vue-router';

export function clearHashGuard(
  from: RouteLocationNormalized,
  to: RouteLocationNormalized,
  failure: void | NavigationFailure | undefined
) {
  // Hash gets cleared properly on Home view
  // And I need to preserve query params on SignIn
  if (!['Home', 'SignIn'].includes(from.name as string)) {
    history.pushState(
      {},
      document.title,
      window.location.pathname + window.location.search
    );
  }
}
But the question remains: why can't Supabase/GoTrue just clear the hash regardless of the redirect URL? I don't think the router has been set up incorrectly, or anything else coming to mind that I should share...