그래서 내 앱의 페이스 북 로그인 작업을하고 있으며 여기에 문제가 있습니다. 어떻게해야합니까?이전에 실패한 경우에만 기능 실행
(1) - 페이스 북에서 인증 (DONE) 2 - 페이스 북에서 도시 탐색 구조 데이터를 검색 (DONE) 3 - 그는 이메일 및 FB 토큰을 사용하여 로그인합니다 않는 경우 - 사용자가 를 존재하는지 확인합니다. - 사용자가 로그인하지 않으면 시스템에서 데이터를 등록하고 자동으로 로그인합니다.
문제는 다음과 같습니다. 여기에 인증 방법과 인증 방법이 있습니다. 내가해야 할 일은 무엇입니까? 호출 인증, 오류가 발생하면 인증 및 등록을 호출해야합니다. 어떻게해야합니까? AngularJS와 에서 NodeJS
에서등록
api.register= function(req, res) {
if (req.body.password!==null) {
var hash = bcrypt.hashSync(req.body.password, bcrypt.genSaltSync(9));
req.body.password= hash;
console.log('Default Login');
}
if(req.body.tokenFB!==null){
var tokenHash = bcrypt.hashSync(req.body.tokenFB, bcrypt.genSaltSync(9));
req.body.tokenFB = tokenHash;
console.log('Login with facebook');
}
userModel.create(req.body)
.then(function(user){
res.json(user);
console.log('We have a new user! =)');
}, function(error){
res.status(500).json(error);
});
};
인증합니다
api.authenticate= function(req, res) {
var email = req.body.email;
console.log(req.body);
userModel.findOne({"email":email})
.then(function(user){
if (user == null) {
res.status(404).json();
}
else {
if (req.body.password!==null && bcrypt.compareSync(req.body.password, user.password)) {
//user found
console.log('default user')
var token = jwt.sign({email:user.email}, app.get('secret'), {
expiresIn: 84600
});
res.set('x-access-token', token);
res.json(user);
} else if (req.body.tokenFB!==null && bcrypt.compareSync(req.body.tokenFB, user.tokenFB)){
console.log('facebook user')
var token = jwt.sign({email:user.email}, app.get('secret'), {
expiresIn: 84600
});
res.set('x-access-token', token);
res.json(user);
}
else {
res.status(404).json();
}
}
}, function(error){
res.status(404).json(error);
});
};
페이스 북 로그인 NodeJS에서는 만약 부분은 분명히 내가 그렇게하려고했던 사촌의 존재, 작동하지 않고 무엇을 보여 I 뭘하려고합니까?
$scope.FBLogin = function(){
firebase.auth().signInWithPopup(provider).then(function(result) {
var token = result.credential.accessToken;
var user = result.user;
$http.get('https://graph.facebook.com/v2.5/me? access_token='+token+'&fields=id,name,first_name,last_name,email')
.success(function(jsonService){
$scope.user.firstName= jsonService.first_name;
$scope.user.lastName = jsonService.last_name
$scope.user.email = jsonService.email;
$scope.user.password=null;
$scope.user.tokenFB=token;
$scope.user=true;
console.log($scope.user);
if($scope.authenticate()){
console.log("Logged in with Facebook! :)")
} else {
$scope.checkingUser=false;
$scope.Register();
$scope.Authenticate();
};
});
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
};
아무도 도와 줄 수 없나요?
$ scope.authenticate() 코드도 게시 할 수 있습니다. –
감사합니다. @BalaAbhinav, 내 문제는 이미 해결했습니다. 하지만 코드는 제 대답에 있습니다! :) –