anyone?
Sep 30, 2016
8
Level 1
Laravel 5.3 session not persistent
Hi all, for the past couple hours i have been trying to get a laravel app to save the session properly. The problem is: When i call "Auth::login($user);" then right after in the same method i call "return Auth::user();" it works however, when i go to a new route and call "return Auth::user();" it returns null. Here is some of the code:
Handle callback method:
public function handleProviderCallback() {
$returnedUser = Socialite::driver('google')->user();
$user = App\User::find($returnedUser->id);
if (is_null($user)) {
$user = new App\User();
$user->id = $returnedUser->id;
$user->email = $returnedUser->email;
$user->confirmed = false;
$user->role = 'unassigned';
}
$user->avatar = $returnedUser->avatar;
$user->save();
Auth::login($user, true);
return Auth::user();
return redirect(route('home'));
}
User
<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, AuthorizableContract
{
use Authenticatable, Authorizable;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['id', 'email', 'role', 'avatar'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [];
/**
* Dates which can be converted into Carbon objects
* @var array
*/
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
}
Any help would be great!
Thanks, Grant
Please or to participate in this conversation.