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
app.json: { "expo": { "scheme": "doko" } }
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);
// Custom redirect scheme
const redirectUri ="https://doko";
// 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"); } };
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
Recommended threads
- I am currently seeking opportunities as ...
Hey! 👋 I'm a Shopify guy. Been building stores for 8+ years. Still haven't lost my mind. Barely. I make stores that don't suck fast, smooth, and actually built...
- Misunderstanding Appwrite Messages for P...
I think I'm having a misunderstanding of how to implement appwrite messages for push notification. I've already setup firebase credentials in appwrite, but I'...
- updateSession isn't working for google o...
I'm building an app using react native with expo. An image of my code is attached. The code is a useEffect that i have in a context that wraps the root layout ...