hi guys, I'm trying to sign with just phone number and it returns existingUser.documents[0] data , but then it just crashes the whole expo app, but it works fine for web
TypeScript
export async function signIn(phone) {
try {
// Delete any active sessions to avoid conflicts
await deleteSession();
// Validate the phone number and check if user exists
await validatePhoneNumber(phone);
console.log("Checking if user with phone number exists...");
const existingUser = await databases.listDocuments(
appwriteConfig.databaseId,
appwriteConfig.userCollectionId,
[Query.equal("phone", phone)]
);
if (existingUser.documents.length > 0) {
console.log("User found, creating a new anonymous session...");
// Create a new anonymous session for the existing user
const session = await account.createAnonymousSession();
console.log("Session created:", session);
return existingUser.documents[0];
} else {
throw new Error("No user found with this phone number.");
}
} catch (error) {
console.error("Error in sign-in:", error.message);
throw new Error("Error in sign-in: " + error.message);
}
}
export async function deleteSession() {
try {
console.log("Deleting all sessions if available...");
const activeSessions = await account.listSessions();
for (const session of activeSessions.sessions) {
await account.deleteSession(session.$id);
}
console.log("All active sessions deleted.");
} catch (error) {
console.error("Error while deleting session:", error.message);
}
}
TL;DR
Issue: The app crashes when trying to sign in with a phone number, but it works fine on web.
Solution: It seems the crash is related to creating an anonymous session for an existing user. Developers can check the code for any bugs or errors in the authentication flow to resolve the crash issue.Recommended threads
- is `account.get()` safe to be used in th...
I want to user's `id` for authentication. However, a while ago I was told in this server not to use `account.get()` and instead add user preferences for that us...
- Courtesy limit reset for non-profit migr...
Hi Team! I'm the architect for a 501(c)(3) non-profit project (Aaria's Blue Elephant) and we just hit our Free plan Database Read limit (currently at 164%). Th...
- {"code": 1008, "message": "Invalid Origi...
Nothing has changed in my application or console settings so I'm curious as to what I need to do to fix this. I already have the client registered so I'm not en...