I have a reactjs app which is using firebase to authenticate a user and also link with various auth provider accounts by using the firebase xxxWithRedirect() methods. For example, the following is invoked from the /users/settings page.
var user = this.props.fb.auth().currentUser;
if (user !== null) {
var provider = new firebase.auth.GoogleAuthProvider();
user.linkWithRedirect(provider).then(function () {
console.log('Successfully linked with Google account');
},
function (error) {
console.log('Failed to link with Google account: code=' + error.code + ' message=' + error.message);
});
}
else {
console.log('user is null');
}
After the authentication is complete, the auth provider redirects back to the app page that originated the redirect. For example:
Navigated to http://localhost:3000/users/settings
In the app route handling, I would like to be able to determine if the initial page load was from a redirect or not. This is so that I can determine whether I should take the user back to the /users/settings page in the case of redirect from auth provider or the / page if the user has not yet been authenticated and is a not an auth redirect page load.
<Switch>
<Route exact path="/" component={Home}/>
<Route exact path="/users/profile" render={() => (isLoggedIn() ? <UserProfile fb={fb}/> : <Redirect to="/"/>)}/>
<Route exact path="/users/settings" render={() => (isLoggedIn() ? <UserSettings fb={fb}/> : <Redirect to="/"/>)}/>
<Route component={NoMatch}/>
</Switch>
Is there a way to tell if a reactjs matching route path is from a redirect?