简体   繁体   中英

How to configure Firebase UI to go back to previous page after sign in

  var uiConfig = {
    signInSuccessUrl: '/',
    signInOptions: [
      // Leave the lines as is for the providers you want to offer your users.
      firebase.auth.GoogleAuthProvider.PROVIDER_ID,
      firebase.auth.FacebookAuthProvider.PROVIDER_ID,
      //firebase.auth.TwitterAuthProvider.PROVIDER_ID,
      //firebase.auth.GithubAuthProvider.PROVIDER_ID,
      firebase.auth.EmailAuthProvider.PROVIDER_ID,
      //firebase.auth.PhoneAuthProvider.PROVIDER_ID,
      //firebaseui.auth.AnonymousAuthProvider.PROVIDER_ID
    ],
      
      callbacks: {
        signInSuccessWithAuthResult: function() {
            window.history.back();
            return false;
        },
      }

I would like to configure the pre built firebase UI so that after the sign in process is completed, it goes back to the page that the user was on before signing in. (I want to use this instead of the signInSuccessUrl because if the user signed in to buy something, I don't want them redirected to a different page. I tried adding in the callback function that should allow me to not use the SignInSuccessUrl, but it isn't working. My plan was to use a callback with window.history.back(); but maybe this wouldn't work? During the firebase sign in process it appears that the browser is redirected several times, so maybe going back by one page in the history wouldn't work? Does anyone know of a better way to do this? I appreciate the help.

Your sign in success URL is set to /

Instead, cut out your call back altogether and set the success URL to the URL that you want.

If it's a dynamic URL, you can use window.location

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