2014-11-18 4 views
0

로그인을 위해 OAuth를 사용하는 첫 번째 Meteor 앱을 개발하고 있습니다. 이전에는 모든 프로젝트에서 계정 비밀번호 부분 만 사용했습니다. Meteor.js loginWithGoogle은 아무 것도하지 않습니다.

내가 구글을 통해 로그인 버튼에 대한 간단한 로그인을 가지고 온

... 
    "click #loginWithGoogle": function(e, t){ 
    Meteor.loginWithGoogle({ 
     requestPermissions: [], 
     loginStyle: "popup" 
    }, function(err) { 
     if (err) { 
     // TODO Need to do something here with the error... 
     console.log('Error: ', err); 
     } else { 
     Router.go('home'); 
     } 
    }); 
    } 
... 

:

<template name="login"> 
    <form id="login" role="form"> 
    <div class="form-group"> 
     <label for="username">Username:</label> 
     <input type="text" id="username" name="username" class="form-control" placeholder="Username" /> 
    </div> 
    <div class="form-group"> 
     <label for="password">Password:</label> 
     <input type="password" id="password" name="password" class="form-control" placeholder="Password" /> 
    </div> 
    <button id="signin" class="btn btn-primary">Sign in</button> 
    <hr /> 
    Or:<br /> 
    <button id="loginWithFacebook">Login with Facebook</button> 
    <button id="loginWithGoogle">Login with Google</button> 
    <button id="loginWithTwitter">Login with Twitter</button> 
    </form> 
</template> 

내가 다음 loginWithGoogle을 버튼 클릭을 캡처하고 호출하는 이벤트 핸들러를 서버 설정 이렇게 Google 용 OAuth :

ServiceConfiguration.configurations.remove({ 
    service: "google" 
}); 
ServiceConfiguration.configurations.insert({ 
    service: "google", 
    clientId: "000000000000000", 
    loginStyle: "popup", 
    secret: "000000000" 
}); 

Accounts.onCreateUser(function (options, user) { 
    console.log('Creating user: ' + user.username); 
    return user; 
}); 

내 길을 내가이 :

if (Meteor.isClient) { 
    // Initialize the loading template before hand 
    Router.onBeforeAction('loading'); 

    // Map the routes 
    Router.map(function() { 
     // Homepage 
     this.route('home', { 
      path: '/', 
      onBeforeAction: function() { 
       if (!Meteor.user()) { 
       console.log('User is not logged in. Displaying login form.'); 
       Router.go('login'); 
       } else { 
       console.log('User is already logged in:', Meteor.user()); 
       } 
      } 
     }); 

     // Login page 
     this.route('login', { 
      path: '/login' 
     }); 
    }); 
} 

그래서, 나는 User is not logged in. Displaying login form. 말을 브라우저에서 콘솔 로그를 얻을, 나는 구글 버튼으로 로그인을 클릭했을 때 구글 계정이 내가 사용하고자하는 팝업 묻는 후 확인 페이지를 얻을. 그러나 동의 단추를 클릭하면 아무 것도 얻을 수 없습니다. Accounts.onCreateUser()이 실행되지 않는 것 같고 loginWithGoogle()의 콜백 코드도 실행되지 않습니다. 콜백이 실행되도록 올바르게 구성하려면 어떻게해야합니까? 궁극적으로 다시 홈페이지로 리디렉션됩니까?

+0

meteor.com에서 프로젝트를 배포 한 다음 로그인이 작동하는지 확인하십시오. Google/서버 또는 코드의 콜백 문제인 경우 적어도 수정해야합니다. –

+0

리디렉션 URL을 처리해야하는지 또는 accounts-google 패키지의 일부로 처리되는지 알고 있습니까? – CodeChimp

+0

Google +로 시도한 적이 없지만 포트 3000에 서비스를 제공하는 것이 문제가있는 FB에 문제가있었습니다. 이것이 공식 meteor.com 사이트에서 모든 것이 상자 밖에서 작동하도록 권장하는 것입니다 (당연히 올바른 클라이언트 ID와 비밀 정보를 제공해야합니다). 패키지가 당신을 위해 아무 것도 리디렉션 (경로 지정)하지 않습니다. –

답변

1

사용자 이름이 지정되지 않았기 때문에 onCreateUser이 작동하지 않습니다.

if(user.services.google) 
     user.username = user.services.google.name 

그리고 그런데

, 왜 당신이 {{>loginButtons}}을 사용하지 않습니다 사용해보십시오?

+0

내가 말했듯이, 이것은 더 복잡한 로그인 과정에서의 첫 번째 시도이기 때문에 나는 {{{loginButtons}}'에 대해 알지 못했습니다. 기본 로그인 페이지. 그러나 나는 확실히 그것을 바꿀 것이다. 또한 onCreateUser 변경에 대한 제안을 시도하고 가능한 한 빨리 작동하는지 확인합니다. – CodeChimp

+0

문제는'{{loginButtons}} '을 사용하지 않고 올바른 사용자를 출력하지 않는 것 같이 보입니다. 올바른 위치에서 나를 가르쳐 주셔서 감사합니다. – CodeChimp

관련 문제