Globe
Globe

Reputation: 305

Supabase Auth - redirectTo not working for OAuth

I am switching from Flutter to Supabase and am running into an issue with Authentication. Although I can successfully launch the URL with the correct redirect value, I keep getting redirected to the site URL which should only be used for web, not iOS or Android. Below is the function I am using for Apple but this is happening with all other providers as well.

const isWeb = Platform.OS === "web";
const redirectTo = isWeb
  ? "https://web.example.com/login-callback/"
  : "com.example.react://login-callback/";

export const signInWithApple = async () => {
  const { data, error } = await supabase.auth.signInWithOAuth({
    provider: "apple",
    options: {
      redirectTo: redirectTo,
    },
  });

  if (error !== null) {
    console.log(error?.message);
    return "error";
  } else {
    console.log(data);
    Linking.openURL(data.url);
    return "success";
  }
};

The URL that gets logged before launching is correct, for example, LOG {"provider": "apple", "url": "https://api.example.com/auth/v1/authorize?provider=apple&redirect_to=com.example.react%3A%2F%2Flogin-callback%2F"}, but I always get redirected to something like https://web.example.com/#access_token=*****. I had a similar issue with Flutter, and that was because I had not added the additional redirect in Supabase but I already did that. I also confirmed that I have CFBundleURLSchemes set in the info.plist for iOS but that did not fix it.

Upvotes: 1

Views: 4066

Answers (1)

Globe
Globe

Reputation: 305

IF SELF-HOSTING:

Check that you do not have spaces after commas in ADDITIONAL_REDIRECT_URLS.

Correct ✅ : ADDITIONAL_REDIRECT_URLS="URL,URL,URL"

Incorrect ❌ : ADDITIONAL_REDIRECT_URLS="URL, URL, URL"

Upvotes: 1

Related Questions