Skip to content
Back

Can not login with OAuth

  • 0
  • React Native
  • Apple
Jeff
15 Sep, 2025, 09:17

Hello everyone i am trying to login with ios and android in react native - expo but it is not successful. And this is the code which i am using to login

TL;DR
Developers are unable to log in with OAuth due to the WebBrowser.openAuthSessionAsync not using the deepLink created in the code. The issue lies in setting the redirectUri. To solve this, make sure to set the redirectUri in this format: `${deepLink}/success` and update the redirect scheme in the app.json file to match the deep link protocol.
Jeff
15 Sep, 2025, 09:18

app.json: { "expo": { "scheme": "doko" } }

Jeff
15 Sep, 2025, 09:18

import { Client, Account, OAuthProvider } from "appwrite"; import { makeRedirectUri } from 'expo-auth-session' import * as WebBrowser from 'expo-web-browser';

const appwriteClient = new Client() .setEndpoint('https://app.doko.so/v1') .setProject('682f5edd0032dee5da20') .setPlatform('com.dokocorp.doko');

const appwriteAccount = new Account(appwriteClient);

const signInWithIos = async () => { try { console.log("appwriteAccount", appwriteAccount);

TypeScript
// Custom redirect scheme

const redirectUri ="https://doko";

TypeScript
// Tạo deep link với expo-auth-session
const deepLink = new URL(makeRedirectUri({}));
console.log("deepLink", deepLink);

const scheme = `${deepLink.protocol}`;
console.log("scheme", scheme);

// Tạo OAuth2 token URL từ Appwrite
const loginUrl = await appwriteAccount.createOAuth2Token(
 OAuthProvider.Apple,
`${deepLink}/success`,
`${deepLink}`,
);

console.log("loginUrl", loginUrl);

// Mở WebBrowser cho login
const result = await WebBrowser.openAuthSessionAsync(
  `${loginUrl}`,
  scheme
);

console.log("result", result);

if (result.type === "success" && result.url) {
  const url = new URL(result.url);
  const secret = url.searchParams.get("secret");
  const userId = url.searchParams.get("userId");

  if (secret && userId) {
    // Tạo session
    await appwriteAccount.createSession(userId, secret);
    Alert.alert("✅ Login success!");
  } else {
    Alert.alert("🚨 OAuth failed", "Cannot get secret/userId");
  }
} else {
  Alert.alert("❌ Login fail");
}

} catch (err: any) { console.error(err); Alert.alert("⚠️ Error", err.message || "Something went wrong"); } };

Jeff
15 Sep, 2025, 09:18

I have configured all the files, I followed the doc, but when calling WebBrowser.openAuthSessionAsync, it does not use the deepLink created from the code

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