Skip to content
Back

Getting 400 Error in Oauth Google Login in production build apk, working locally properly

  • 1
  • React Native
veerbal
18 Jan, 2025, 07:14

Hi, I am building React Native app, here I am using AppWrite auth in React Native Expo. I have been building it for last few days. it is working properly but today i created its build apk, and when i tried to login using Google Oauth. It started giving Wierd error. I though production envs are missing, but they there properly. I have attached screenshot of the issue.

TL;DR
Developers are experiencing a 400 Error in the Google OAuth login on the production build APK, while it is working fine locally in Expo. They are missing success and failure URLs. The issue may be due to the absence of these URLs.
Darshan Pandya
18 Jan, 2025, 07:48

what are the success and failure urls?

veerbal
18 Jan, 2025, 07:51

Not provided any success or failure URL I guess. Because it is working properly Expo dev on my system, but giving this error when I build apk of it.

veerbal
18 Jan, 2025, 07:51

Please check this auth code:

const login = async (): Promise<boolean> => { try { const redirectURI = Linking.createURL("/"); const response = await account.createOAuth2Token( OAuthProvider.Google, redirectURI );

TypeScript
if (!response) {
  throw new AuthError("OAuth2 response was empty");
}

const browserResult = await openAuthSessionAsync(
  response.toString(),
  redirectURI
).catch((error) => {
  throw new AuthError("Failed to open auth session", error);
});

if (browserResult.type !== "success") {
  throw new AuthError(`Auth session failed: ${browserResult.type}`);
}

const url = new URL(browserResult.url);
const secret = url.searchParams.get("secret");
const userId = url.searchParams.get("userId");

if (!secret || !userId) {
  throw new AuthError(
    "Missing authentication parameters from callback URL"
  );
}

const session = await account
  .createSession(userId, secret)
  .catch((error) => {
    throw new AuthError("Failed to create session", error);
  });

if (!session) {
  throw new AuthError("Session creation returned empty response");
}

return true;

} catch (error) { if (error instanceof AuthError) { console.error(Authentication failed: ${error.message}, error.cause); } else { console.error("Unexpected authentication error:", error); } return false; } };

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