loginWithFacebook - Redirect to /dashboard after login?


#1

After the user has logged into my application with Facebook they are redirected the the home page. Is there any way to change this so I can redirect the user to /dashboard for example?

I am using Meteor.loginWithFacebook. The login button is on the homepage. I am also using react-router. I use the redirect flow instead of popup. All works fine. After the user has logged in they are redirected back to the homepage.

This is not what I want. Instead I want to redirect the user to /dashboard, I know I can change the redirectUrl in the loginWithFacebook options, but I wasn’t sure how or whether or not it would be a wise idea to change it from the default _oauth/facebook.

Is it possible to some how redirect the logged in user from Facebook to /dashboard. Can I hook into _oauth/facebook some how?


#2

Ok, so I have discovered that if I call the button from the dashboard page via console it will redirect to the last page the user was on when the login button was pressed. This means theoretically I should be able to push the url into react-router history before calling loginWithFacebook. Something along those lines anyway. Will test it out.


#3

I figured it out. The documentation shows loginWithFacebook accepts a redirectUrl property. I simply set this to the dashboard URL. After the user has logged in they will be redirected to the dashboard.

To show an example here is the click handler for button component I created. When the user clicks they are redirected to accept the Facebook application permissions, once complete they will be redirected to the dashboard route:

handleClick = () => {
    Meteor.loginWithFacebook(
        { 
            requestPermissions: this.props.permissions,
            loginStyle: this.props.loginStyle,
            redirectUrl: Meteor.absoluteUrl('dashboard'),
        },
        err => {
            // These will be unsed when using redirect flow
            if (err) return this.props.onError(err)
            return this.props.onSuccess()
        }
    )
}

Ideally the redirect URL should be passed in as a prop but did it this way to demonstrate.


#4

Does everything works fine now?


#5

Yep, all is well. The meteor documentation is fantastic.