How to redirect after a user signs in with Firebase authentication?

后端 未结 4 1475
孤独总比滥情好
孤独总比滥情好 2020-12-03 06:35

How can I redirect to a different webpage after the user has signed in?

Currently when a user logs in, data gets retrieved however, it doesn\'t redirect the user to

4条回答
  •  时光取名叫无心
    2020-12-03 06:55

    If you're building a single-page style application, you likely don't need to redirect. Instead you would just change your application state when the user logs in. If you do want to change the URL, however, you can simply set the window location using JavaScript in your success callback. For example:

    window.location = '/logged_in.html'
    

    Note that on the new page you will need to listen for the auth state as well:

    firebase.auth().onAuthStateChanged(function(currentUser) {
      if (currentUser) {
        // the user is logged in, you can bootstrap functionality now
      }
    });
    

    In general Firebase applications on the web will work better if you don't structure your app to need hard page loads in between state transitions. Everything can and ideally should be managed using JavaScript without requiring an extra page load.

提交回复
热议问题