简体   繁体   中英

switch login screen to home firebase and google

I have no idea how I can get through the google login from the login to home screen

I want to perform an action that when the user clicks login with google it checks if it's right and goes straight to home

<!-- language: Js -->
screen config Firebase


    import { initializeApp } from "firebase/app";
    import { getAuth, GoogleAuthProvider, signInWithPopup } from "firebase/auth";
  
    const firebaseConfig = {
      apiKey: "AIzaSyADaTNLtR-zJyY2JGbiIjxEqyIRSEvOB0g",
      authDomain: "projetotcc-d6d47.firebaseapp.com",
      databaseURL: "https://projetotcc-d6d47-default-rtdb.firebaseio.com",
      projectId: "projetotcc-d6d47",
      storageBucket: "projetotcc-d6d47.appspot.com",
      messagingSenderId: "1041839304552",
      appId: "1:1041839304552:web:e862a59abc6c747d6730dd",
      measurementId: "G-D8CEEJPRVS"
    };


    const app = initializeApp(firebaseConfig);
    export const auth = getAuth(app);

    const provider = new GoogleAuthProvider();

    export const signInWithGoogle = () => {

      signInWithPopup(auth, provider)
        .then((result) => {
          const name = result.user.displayName;
          const userid = result.user.uid;
          const email = result.user.email;
          const profilePic = result.user.photoURL;


          localStorage.setItem("name", name);
          localStorage.setItem("email", email);
          localStorage.setItem("userid", userid);
          localStorage.setItem("profilePic", profilePic);
         
        })
        .catch((error) => {
          console.log(error);
        });

        
    };

You need to set-up a listener that will check whether a user is logged in or not, and depending on this display either the authentication screen or the home screen.

Check this doc to know how to do this and an example. Also, this doc for sing-in with Google.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM