Monday, 28 March 2022

Why do I get UNKNOWN/CUSTOM URL SCHEME error in React Native Expo Google/Facebook login?

I have a react native expo managed workflow project with Firebase backend set up. On android emulator facebook and google login WORKS with firebase, however when I release the apk (expo build:android) I get the following error during redirect: "UNKNOWN/CUSTOM URL SCHEME"

I use the following packeges: Google with expo-auth-session Facebook with expo-facebook

enter image description here

Since it works in emulator, I am pretty sure my Secrets, ID's and redirect URL's are okay, it redirects me without any problem. Also firebase created the google cloud profile for me, I just added the valid Oauth redirect URI's to my WEB ID settings. Same for facebook, added the firebase redirect URL, as well as the expo one.

I tried to add "scheme":"myapp" to app.json, but no luck. Not sure what to do...

import {GoogleAuthProvider, FacebookAuthProvider, signInWithCredential} from 'firebase/auth';
import * as Facebook from 'expo-facebook';
import * as Google from 'expo-auth-session/providers/google';
import * as WebBrowser from 'expo-web-browser';

WebBrowser.maybeCompleteAuthSession();

//Google
const [request, response, promptAsync] = Google.useIdTokenAuthRequest(
    {
      clientId: 'xxxxxxxxxxxxxxxxxxxx24u2l7k576m03n.apps.googleusercontent.com',
      redirectUriOptions: {
        // scheme: 'com.graphite.ekisallatkonyv',
        useProxy: true,
      },
      },
  );
  React.useEffect(() => {
    if (response?.type === 'success') {
        const { id_token } = response.params;
  
        const credential = GoogleAuthProvider.credential(id_token);
        signInWithCredential(auth, credential)
        .then((result) => {
            addDefaultData(result.user.uid)
        });
    }
  }, [response]);


const google_login_ButtonClick = async() => {
    promptAsync({useProxy: true,showInRecents: true})
}


const facebook_login = async() => {
    try {
        await Facebook.initializeAsync({
          appId: FBAPPID,
        });
        const { type, token } =
          await Facebook.logInWithReadPermissionsAsync({
            permissions: ['public_profile', 'email'],
          });
        if (type === 'success') {
          const credential = FacebookAuthProvider.credential(token)
          signInWithCredential(auth, credential)
          .then((result) => {
            addDefaultData(result.user.uid)
          })
        } else {
          // type === 'cancel'
        }
      } catch ({ message }) {
        Alert.alert(`ERROR: ${message}`);
      }
}


from Why do I get UNKNOWN/CUSTOM URL SCHEME error in React Native Expo Google/Facebook login?

No comments:

Post a Comment