Skip to content
Init is coming / May 19 - 23
Back

Appwrite Google auth not working in production React Native APK built with EAS

  • 0
  • React Native
  • Cloud
Pranta Barua
28 Dec, 2024, 14:53

I tried creating an apk with EAS the apk built successfully i have also set all the environment vars in EAS project dashboard, and set the in the 'app.json', the problem is whenever i try to login with Google i get this 400 ERROR message in browser, i had re-check every credentials its working fine in development with expo go.

https://github.com/pranta-barua007/react-native-properties

TL;DR
Developers encountered an issue with Google authentication in a React Native APK built with EAS. They tried a solution from a blog but still faced a new error. The problem seems to be with the implementation. Make sure all environment variables are set correctly. The link provided may offer additional insights.
Pranta Barua
28 Dec, 2024, 14:54

it works well in developement and i think the issue relies in the implementation, here i found a source -> https://bishwajeet-parhi.medium.com/i-built-an-auth-template-powered-by-react-native-and-appwrite-4a0b7ee90ba6

Pranta Barua
28 Dec, 2024, 14:55

i have tried the solution from above blog and re implemented login function

Pranta Barua
28 Dec, 2024, 14:55
TypeScript
 export async function login() {
    try {
      let redirectScheme = makeRedirectUri({ preferLocalhost: true, isTripleSlashed: false });
      
      //HACK: localhost is a hack to get the redirection possible
      if (process.env.EXPO_PUBLIC_DEV_MODE !== 'true' && !redirectScheme.includes('localhost')) {
        redirectScheme = `${redirectScheme}localhost/`;
      }
      
      //const redirectUri = Linking.createURL('/', { scheme: redirectScheme });
  
      const responseURL = account.createOAuth2Token(
        OAuthProvider.Google,
        redirectScheme
      );
      if (!responseURL) throw new Error("Create OAuth2 token failed");

      // console.log({responseURL});
  
      const browserResult = await openAuthSessionAsync(
        responseURL.href,
        redirectScheme
      );

      // console.log({browserResult});
      if (browserResult.type !== "success")
        throw new Error("Create OAuth2 token failed");
  
      const url = new URL(browserResult.url);
      
      const secret = url.searchParams.get("secret")?.toString();
      const userId = url.searchParams.get("userId")?.toString();
      if (!secret || !userId) throw new Error("Create OAuth2 token failed");
  
      const session = await account.createSession(userId, secret);
      if (!session) throw new Error("Failed to create session");
  
      return true;
    } catch (error) {
      console.error(error);
      return false;
    }
  }
Pranta Barua
28 Dec, 2024, 14:56

the previous error hasbeen solved the google account shows finally BUT there is new error! if i tab Go Back the app works normally

Pranta Barua
28 Dec, 2024, 14:56
Pranta Barua
28 Dec, 2024, 14:58

NB: i have also tried with out / the result is same

TypeScript
//HACK: localhost is a hack to get the redirection possible
      if (process.env.EXPO_PUBLIC_DEV_MODE !== 'true' && !redirectScheme.includes('localhost')) {
        redirectScheme = `${redirectScheme}localhost`;
      }
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more