안녕하세요. 플러터로 앱 개발 중에 문의사항이 있어 글을 작성합니다.
카카오톡 로그인을 구현하였는데, 에뮬레이터에서는 잘 실행이 되는데, 기기에 연결하거나 플레이스토어에서 다운로드해서 사용하면 로그인 화면으로도 넘어가지 않습니다. 혹시 어떻게 해결하면 될까요???
#index.js
// Kakao Login API
const functions = require("firebase-functions");
const admin = require("firebase-admin");
var serviceAccount = require("./withboard-6fa32-firebas*******************************.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://***********************.firebaseio.com"
});
exports.createCustomToken = functions.https.onRequest(async (request, response) => {
try {
const user = request.body;
console.log("Received user data: ", user);
const uid = `kakao:${user.uid}`;
const updateParams = {
email: user.email,
displayName: user.displayName,
};
try {
await admin.auth().updateUser(uid, updateParams);
} catch (e) {
updateParams["uid"] = uid;
await admin.auth().createUser(updateParams);
}
const token = await admin.auth().createCustomToken(uid);
response.send(token);
} catch (error) {
console.error("Error while executing function: ", error);
response.status(500).send("Internal Server Error");
}
});
#kakaosignin.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart';
import 'auth/social_login.dart';
class KakaoLogin implements SocialLogin {
@override
Future<bool> login() async {
try {
bool isInstalled = await isKakaoTalkInstalled();
if (isInstalled) {
try {
await UserApi.instance.loginWithKakaoTalk();
User user = await UserApi.instance.me();
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
final CollectionReference _users = _firestore.collection('users');
await _users.doc("kakao:${user.id}").set({
'email': user.kakaoAccount!.email,
'name': user.kakaoAccount!.profile!.nickname,
});
return true;
} catch (e) {
return false;
}
} else {
try {
await UserApi.instance.loginWithKakaoAccount();
print(await KakaoSdk.origin);
User user = await UserApi.instance.me();
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
final CollectionReference _users = _firestore.collection('users');
await _users.doc("kakao:${user.id}").set({
'email': user.kakaoAccount!.email,
'name': user.kakaoAccount!.profile!.nickname,
});
return true;
} catch (e) {
print(await KakaoSdk.origin);
return false;
}
}
} catch (e) {
return false;
}
}
@override
Future<bool> logout() async {
try {
await UserApi.instance.logout();
return true;
} catch (error) {
return false;
}
}
}
앱 ID 948294