0

I'm testing satellizer example with Laravel back end for Facebook, once user links the Facebook account to the app its impossible to unlink it with satellizer, whenever user clicks Facebook Unilink button it gives 404 error,

http://localhost:8000/auth/unlink 

404 Not found. But on Laravel router.

Route::get('auth/unlink/{provider}', ['middleware' => 'auth', 'uses' => 'AuthController@unlink']);

Please help me to fix this bug.

Zarah Dewayne
  • 75
  • 1
  • 7

1 Answers1

0

Did you find the solution for this?

After check the below link I end up founding a solution for my issue. https://github.com/sahat/satellizer/issues/269

Basically in the Satellizer documentation explain that provider and httpOptions was the parameters you can send via the unlink call, however, the options never gets passed as it only retrieves the information from the first parameter which is the provider.

You can see a bit more about the accepted parameters in the piece of code below that is inside of the satellizer.js file.

OAuth.prototype.unlink = function (provider, httpOptions) {
        if (httpOptions === void 0) { httpOptions = {}; }
        httpOptions.url = httpOptions.url ? httpOptions.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.unlinkUrl);
        httpOptions.data = { provider: provider } || httpOptions.data;
        httpOptions.method = httpOptions.method || 'POST';
        httpOptions.withCredentials = httpOptions.withCredentials || this.SatellizerConfig.withCredentials;
        return this.$http(httpOptions);
    };

My not so elegant solution is as below:

html

<button class="btn btn-sm btn-danger float-left" ng-if="user.facebook"
ng-click="unlink({provider:'facebook', options: {'param1':'value','param2':'value2'}})"><i class="ion-social-facebook"></i> Unlink Facebook Account
</button>

I have basically wrapped the information I want to send by the variable provider (renamed to just data) in the JS code below.

//unlink a social login profile from user's profile
        $scope.unlink = function (data) {
            console.log(data);
            $auth.unlink(data)
                .then(function () {
                    toastr.info('You have unlinked a ' + data.provider + ' account');
                    $scope.getProfile();
                })
                .catch(function (response) {
                    toastr.error(response.data ? response.data.message : 'Could not unlink ' + data.provider + ' account', response.status);
                });

The JSON sent via view does not look pretty but works:

provider    Object
    provider    "facebook"
    options Object
    flag    "unlink"
    view    "profile"
    userId  236

Nothing of the above resolved the 404 issue but resolve the passing of parameters from the original satellizer unlink function.

The issue with the route happens because Laravel is blocking that route in the file Authenticate.php inside of the function "public function handle($request, Closure $next)"

You can ether route without the middware like this

Route::post('auth/unlink', 'AuthController@unlink');
Route::get('auth/unlink', 'AuthController@unlink');
Route::any('auth/unlink', 'AuthController@unlink');

The above will make sure the call will hit the controller one whay or another. how you are getting the parameters in the controller will depend if you choose post/get/any. Meaning you will retrieve the parameters via Laravel variable $request from

public function unlink(Request $request)

or using the Input facade like this

$input = Input::all();

in here you can do whatever you want with the variable values passed. Now is up to you on the handling.

Note: The satellizer code sets by default the method to POST if no method is passed in the httpOptions as you can see below:

 OAuth.prototype.unlink = function (provider, httpOptions) {
    if (httpOptions === void 0) { httpOptions = {}; }
    httpOptions.url = httpOptions.url ? httpOptions.url : joinUrl(this.SatellizerConfig.baseUrl, this.SatellizerConfig.unlinkUrl);
    httpOptions.data = { provider: provider } || httpOptions.data;
    httpOptions.method = httpOptions.method || 'POST';
    httpOptions.withCredentials = httpOptions.withCredentials || this.SatellizerConfig.withCredentials;
    return this.$http(httpOptions);
    };

That does not really helps when the code with the Laravel example comes with the route calling the get method not the post and in the js example no options of http is set to get. Meaning you are trying to call get where post is the default therefore the route will never work.

Sorry if I am not more clear as this is my first time trying to put my thinking here and English is not really my first language.

Good luck.