简体   繁体   中英

Laravel Socialite - handleProviderCallback() method not showing stored session

I am trying to integrate Socialite in my Laravel project. I am trying to store a session in buyerSignup.blade.php file and then trying to get that session value in Socialite's handleProviderCallback() method. But it is not showing any value don't know why. Although the other method redirectToProvider() showing the session value.

I need that session value in handleProviderCallback() method to process it and take actions based upon the value of session. Below is a actual of code that I am using.

Storing a session value in buyerSignup.blade.php

@php

\Session::put('buyerSignupFb','true');

@endphp

Trying to get the above stored value in LoginController's handleProviderCallback() method.

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Auth;
use App\sellerData;
use App\buyerData;
use App\sellerDealCat;
use App\subCatData;
use App\Session;
use App\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\DB;
use Socialite;

class LoginController extends Controller
{

  use AuthenticatesUsers;

 protected $redirectTo = '/home';

 public function __construct()
    {
        $this->middleware('guest')->except('logout');
        $this->middleware('guest:seller')->except('logout');
        $this->middleware('guest:buyer')->except('logout');

    }


public function redirectToProvider()

{

return Socialite::driver('facebook')->redirect();


}

public function handleProviderCallback()
{

//cant get the value of the session defined in buyerSignup.blade.php
// echo doesn't work too

return \Session()->get('buyerSignupFb');


}

}

Any suggestion what I am doing wrong or how to make it work. TIA

U doing all good, but not enought, first u set a redirect provider

public function redirectToProvider()

{
     return Socialite::driver('facebook')->stateless()->redirect();
}

it's good, when user will give access to his token, u need to handle callback in handleProviderCallback() , where u need to exchange user auth code to acces token . All of this socialite makes automatically, all what u need its just call it

public function handleProviderCallback()
{
    $externalUser = Socialite::driver('facebook')->stateless()->user();

\\check if user exists, if not create

    $auth->login($user, true);

    if ($user->type = 'seller'){$this->redirectTo = '/forSellers'} else {$this->redirectTo = '/forOtherGroup'}

    return redirect($this->redirectPath());
}

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