Skip to content

Instantly share code, notes, and snippets.

@kimyongin
Last active February 24, 2016 10:38
Show Gist options
  • Save kimyongin/0c3693c03181bb6cbba6 to your computer and use it in GitHub Desktop.
Save kimyongin/0c3693c03181bb6cbba6 to your computer and use it in GitHub Desktop.
function kakaoLogin(callback) {
// 소셜 로그인창을 띄운다
Kakao.Auth.login({
success: function (authObj) {
// 소셜 로그인 성공
Kakao.API.request({
url: '/v1/user/me',
success: function (response) {
// 소셜 정보 가져오기
var userName = response.properties.nickname;
var userId = response.id;
// 소셜ID로 로컬 로그인
localLogin({ userId: userId }, function (response, data) {
if (response.status == 200) {
// 로컬 로그인 성공
callback(response, data);
} else {
// 로컬 로그인 실패 (--> 소셜로그인을 처음한 경우)
// 로컬 가입
localSignup(
{
type: "kakao",
userId: userId,
userData: { userName: userName }
}, callback);
}
});
},
fail: function (error) {
alert(JSON.stringify(error))
}
});
},
fail: function (err) {
alert(JSON.stringify(err))
}
});
}
// -------------------------------------
kakaoLogin(function (response, data) {
if (response.status == 200) {
toastr.success(data, 'Welcome');
$uibModalInstance.close();
} else {
toastr.error(data, "Login Failed");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment