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

Google Authentication Not Working In Preview APK (React Native)

  • 0
  • General
  • React Native
  • Auth
Naman dev
27 Mar, 2025, 06:42

code :

`import { Account, Avatars, Client, Databases, ID, OAuthProvider, Query } from "react-native-appwrite"; import * as Linking from "expo-linking"; import { openAuthSessionAsync } from "expo-web-browser";

const DATABASE_ID = process.env.EXPO_PUBLIC_APPWRITE_DATABASE_ID!; const COLLECTION_ID = process.env.EXPO_PUBLIC_APPWRITE_COLLECTION_ID!; const SAVED_MOVIES_COLLECTION_ID = process.env.EXPO_PUBLIC_APPWRITE_SAVED_MOVIES_COLLECTION_ID!;

const client = new Client() .setEndpoint(process.env.EXPO_PUBLIC_APPWRITE_ENDPOINT!) .setProject(process.env.EXPO_PUBLIC_APPWRITE_PROJECT_ID!)

const avatar = new Avatars(client); const account = new Account(client);

const database = new Databases(client);

export async function login(urlParam:string) { try { const redirectUri = Linking.createURL(urlParam);

TypeScript
const response = await account.createOAuth2Token(
  OAuthProvider.Google,
  redirectUri
);

if (!response) throw new Error("Create OAuth2 token failed");
console.log("response", response)

const browserResult = await openAuthSessionAsync(
  response.toString(),
  redirectUri
);
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.log(error); return false; } } `

During Developer It's working Properly Once Create Build And Release Preview APK it's giving below error when we click continue to login button

Error 400 Invalid success param: URL host must be one of: localhost, cloud.appwrite.io, appwrite.io, .appwrite.io, Type : general_argument_invalid

TL;DR
Developers are experiencing Google authentication issues in their React Native app's Preview APK. The error "Error 400: Invalid 'success' param" occurs when clicking the login button. The issue may be due to the URL host being required to match specific criteria. To resolve this, ensure the correct URL host (localhost, cloud.appwrite.io, appwrite.io, or .appwrite.io) is used for success parameter in the OAuth authentication flow.
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