Skip to content
Back

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

  • 0
  • React Native
ALEN P AJI
28 Feb, 2025, 17:22

export const client = new Client(); client .setEndpoint(config.endpoint!) .setProject(config.projectId!) .setPlatform(config.platform!);

export const avatar = new Avatars(client); export const account = new Account(client); export const databases = new Databases(client); export async function login() { try { const redirectUri = Linking.createURL('/');

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

    console.log(response)

    if (!response) throw new Error("Create OAuth2 token failed");




    const browserResult = await openAuthSessionAsync(
        response.toString(),
        redirectUri,
    );

    //console.log(browserResult);




    if (browserResult.type !== "success")
        throw new Error("Create browser 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;
}

}

TL;DR
Error 400Invalid success param: URL host must be one of: localhost, cloud.appwrite.io, appwrite.io;. OAuth2 with React Native isn't fully supported. For React Native, check: <https://github.com/appwrite/sdk-for-react-native/issues/34#issuecomment-2654940715>. Make sure to format code correctly. Problem arises when moving to APK.
ALEN P AJI
28 Feb, 2025, 17:23

it was woking fine on npx epo start but when i made it to an apk i got this error please help

Steven
28 Feb, 2025, 17:52

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting).

Steven
28 Feb, 2025, 17:52

OAuth2 with React Native is not fully supported. The GitHub comment explains the current state: https://github.com/appwrite/sdk-for-react-native/issues/34#issuecomment-2654940715

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