0

Google 인증을 사용하여 사용자를 인증하려고합니다. 인증을 받아야하지만 로그인 후 사용자를 리디렉션하는 방법 및 로그 아웃 방법을 알지 못합니다.Oauth 2 Google 사용

Google 문서 (https://developers.google.com/identity/sign-in/web/sign-in)를 사용해 보겠습니다. 하지만 오류가 있습니다 : Cannot read property 'getAuthInstance' of undefined.

<script src="https://apis.google.com/js/platform.js" async defer></script> 
<script> 
    var redirectUri = 'http://localhost:4200/list'; 
    function onSignIn(googleUser) { 

     var profile = googleUser.getBasicProfile(); 
     console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead. 
     console.log('Name: ' + profile.getName()); 
     console.log('Image URL: ' + profile.getImageUrl()); 
     console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present. 
    } 
    function signOut() { 
     var auth2 = gapi.auth2.getAuthInstance(); 
     auth2.signOut().then(function() { 
      console.log('User signed out.'); 
     }); 
    } 
</script> 

사람이 그것을 해결하는 방법을 알고 있나요

: 여기

코드인가?

답변

0

스크립트에 gapi.auth2.init() 방법을 사용하거나 을 <head>에 입력해야합니다.

코드는 다음과 같습니다

<meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com"> 
<script src="https://apis.google.com/js/platform.js" async defer></script> 
<script> 
    var redirectUri = 'http://localhost:4200/list'; 
    function onSignIn(googleUser) { 
     var profile = googleUser.getBasicProfile(); 
     console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead. 
     console.log('Name: ' + profile.getName()); 
     console.log('Image URL: ' + profile.getImageUrl()); 
     console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present. 
    } 
    function signOut() { 
     var auth2 = gapi.auth2.getAuthInstance(); 
     auth2.signOut().then(function() { 
      console.log('User signed out.'); 
     }); 
    } 
</script> 
gapi.auth2.init() 방법에

더 많은 정보 : https://developers.google.com/identity/sign-in/web/reference#gapiauth2initwzxhzdk19paramswzxhzdk20