My app has a KakaoTalk login feature. However, currently, the KakaoTalk login feature works well on all devices such as iphone and android, but only on ipad (all ipad, not specific ipad), the KakaoTalk login feature does not work.
I tried to figure out how to do it, but couldn't come up with a good way.
const doSignInWithKakao = async () => {
try {
const token = await login();
if (!token) {
throw new Error("Failed to get Kakao token");
}
const profileResult = await getProfile(token.accessToken);
if (!profileResult) {
throw new Error("Failed to get Kakao profile");
}
let { email, nickname, phoneNumber } = profileResult;
if (phoneNumber.startsWith("+82")) {
phoneNumber = "010" + phoneNumber.slice(6);
}
const db = firebase.firestore();
const usersRef = db.collection("users");
const snapshot = await usersRef
.where("phoneNumber", "==", phoneNumber)
.get();
if (!snapshot.empty) {
for (const doc of snapshot.docs) {
// 변경: forEach -> for...of
const userData = doc.data();
try {
await signIn(userData.email, userData.password, navigation);
console.log("Kakao logged in with existing account");
} catch (err) {
console.error(err); // 에러 로깅
Alert.alert(
"Login failed!",
"Could not sign in with existing account."
);
}
}
} else {
// No existing account with the same mobile number, register
const randomPassword = Math.random().toString(36).slice(-8); // Generate a random password
try {
await registration(
nickname,
email,
randomPassword,
phoneNumber,
navigation
);
console.log("Kakao registration successful");
} catch (err) {
console.error(err); // 에러 로깅
Alert.alert(
"Registration failed!",
"Could not register new account."
);
}
}
} catch (error) {
console.error(error); // 추가적인 에러 로깅
Alert.alert("Login with Kakao failed!", "Please try again later.");
}
};