Skip to content
Back

Login error on my react native development server

  • 1
  • React Native
  • Auth
ZHÄDØW999
29 Dec, 2024, 00:59

I get this this error when I try to login with Google on my react native development server app "Error 400 Invalid success param: URL host must be one of: localhost, cloud.appwrite.io, appwrite.io, *

Type

general_argument_invalid"

The login works fine when I open the app using expo go but not on my development app

TL;DR
Developers are encountering a login error on their React Native development server. The issue was resolved by adjusting the redirectUri and adding the app ID in the Google console platform.
D5
29 Dec, 2024, 04:54

Hello! Probably that means you need to add the app into the console platforms. In the overview section, you can go to the bottom of the page and add it.

D5
29 Dec, 2024, 04:54

If not, what's the redirect URL that you have set?

ZHÄDØW999
29 Dec, 2024, 06:45

I set it to " * "

D5
29 Dec, 2024, 09:07

In the console?

D5
29 Dec, 2024, 09:07

You need to add the app id like com.example.myapp

ZHÄDØW999
29 Dec, 2024, 09:34

Do you mean the Google console ?

ZHÄDØW999
29 Dec, 2024, 09:40

Or the Appwrite dashboard?

D5
29 Dec, 2024, 15:10

Appwrite

ZHÄDØW999
29 Dec, 2024, 15:54

this my login code export async function login() { try { const redirectUri = Linking.createURL("/"); const redirectUri1 = Linking.createURL("http://localhost:8081/");

TypeScript
    const response = await account.createOAuth2Token(
      OAuthProvider.Google,
      redirectUri,
      redirectUri1
      
    );
    if (!response) throw new Error("Create OAuth2 token failed");

    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 a session");

    return true;
  } catch (error) {
    console.error(error);
    return false;
  }

}

faye
30 Dec, 2024, 08:49

it's a web based RN

faye
30 Dec, 2024, 08:49

otherwise the redirectUri doesn't make sense in the first place

ZHÄDØW999
30 Dec, 2024, 13:44

Oh, that is the URL I get in my terminal when I start an expo server so I thought that will work

faye
30 Dec, 2024, 14:18

Are you using web only?

ZHÄDØW999
30 Dec, 2024, 14:23

Nope was using expo go , and the Appwrite google login was working just fine , but when I switched to a development build, I got that error

ZHÄDØW999
30 Dec, 2024, 14:23

When I try to log in

ZHÄDØW999
30 Dec, 2024, 14:26

Also I'm kinda new to Appwrite and react native 😅

ZHÄDØW999
30 Dec, 2024, 18:40

Yo 😭👀

darfdx
30 Dec, 2024, 23:30

Had the same issue on this thread along with some other quirks you should be aware of, at least if you are using Android to test:

https://discord.com/channels/564160730845151244/1320926689387089930

ZHÄDØW999
31 Dec, 2024, 09:52

heyyy thank you for this was able to fix it kinda but i got this after i log in , this is my login code export async function login() { try {

TypeScript
    const redirectUri = new URL(Linking.createURL('/',{isTripleSlashed:false}));
    if(!redirectUri.hostname){
        redirectUri.hostname='localhost'
    }
    // const redirectUri1 = Linking.createURL("http://localhost:8081/");

    const response = await account.createOAuth2Token(
      OAuthProvider.Google,
      redirectUri.toString(),
    //   redirectUri1
      
    );
    console.log(redirectUri)
    if (!response) throw new Error("Create OAuth2 token failed");

    const browserResult = await WebBrowser.openAuthSessionAsync(
      response.href.toString(),
      redirectUri.toString(),
    );
    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 a session");

    return true;
  } catch (error) {
    console.error(error);
    return false;
  }

}

ZHÄDØW999
31 Dec, 2024, 10:00

Didn't really understand what you guys did after to fix that 🤲

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