Others

Firebase: 소셜 로그인

selonjulie 2022. 9. 12. 23:39

Authenticate Using Google with JavaScript 

 

자바스크립트로 Google을 사용하여 인증  |  Firebase

Google은 흑인 공동체를 위한 인종적 평등을 추구하기 위해 노력하고 있습니다. 자세히 알아보기 의견 보내기 자바스크립트로 Google을 사용하여 인증 알림 이 페이지를 개발자 프로필에 저장하여

firebase.google.com

 

 

Create an instance of the Google provider object

import { GoogleAuthProvider } from "firebase/auth";

const provider = new GoogleAuthProvider();

 

Authenticate with Firebase using the Google provider object. You can prompt your users to sign in with their Google Accounts either by opening a pop-up window or by redirecting to the sign-in page. The redirect method is preferred on mobile devices.


To sign in with a pop-up window, call signInWithPopup:

import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth";

const auth = getAuth();
signInWithPopup(auth, provider)
  .then((result) => {
    // This gives you a Google Access Token. You can use it to access the Google API.
    const credential = GoogleAuthProvider.credentialFromResult(result);
    const token = credential.accessToken;
    // The signed-in user info.
    const user = result.user;
    // ...
  }).catch((error) => {
    // Handle Errors here.
    const errorCode = error.code;
    const errorMessage = error.message;
    // The email of the user's account used.
    const email = error.customData.email;
    // The AuthCredential type that was used.
    const credential = GoogleAuthProvider.credentialFromError(error);
    // ...
  });

 

Firebase -> Console -> Authentication -> Users

에서 사용자가 생겼는지 확인