React Developer
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
Votes
0
Replies
3
Participants
Unknown
Messages
4
React Developer
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
React Developer
app.json: {
"expo": {
"scheme": "doko"
}
}
React Developer
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");
}
};
React Developer
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