0

I am trying to log a user in via Facebook and then use that user data to fill out the name and email in a comment form.

I am using Laravel / Socialite.

So in my LoginController I have this:

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

use Socialite;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function redirectToProvider()
    {
        return Socialite::driver('facebook')->redirect();
    }

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

        return redirect()->route('blog');


        // $user->token;
    }
}

By using breakpoints in both methods I came to the conclusion that the handleProviderCallback method is actually never triggered for some reason.

So to make it clear, redirectToProvider is triggered and it works, it does log me in via Facebook, but the handleProviderCallback method is never triggered so I can't get user data.

jukenduit
  • 322
  • 3
  • 15

1 Answers1

0

first please check your function definition it is wrong

public function public function handleProviderCallback(Request $request)
{

and to store data in session you can also use

Session::put(['key' => 'value']);
sandip bharadva
  • 629
  • 1
  • 6
  • 19
  • I just pasted the whole controller, however I've edited my Q, the issue is not with sessions but the method `handleProviderCallback` is never triggered. – jukenduit Aug 10 '19 at 13:43