I'm starting out a new Laravel 5.2 project, and I've run into a strange authentication problem: Auth::check()
returns false constantly.
If you think this is a duplicate, read on. I've tried multiple suggestions to fixing this issue with no luck.
The setting:
- The application environment is Laravel Homestead's
php-7
branch (Vagrant box). - User models use UUIDs instead if IDs (table has auto-incrementing
id
switched to a 36-characteruuid
primary key column). - User model
primaryKey
has been changed fromid
touuid
andincrementing
has been set to false. - Used
artisan make:auth
to generate authentication baseline to work with. - Authentication routes have been set for
getLogin
,postLogin
,getEmail
,postEmail
,getReset
andpostReset
and they are working fine. web
middleware is used for all routes in the application at the moment.- Auth config and session config inside
config
dir are at defaults (except a namespace change for auth model). - Passing in invalid credentials triggers validation errors properly.
- After logging in the
redirectPath
onAuthController
does work, but theguest
middleware hijacks the request and redirects user back to login route.
I can create users fine and change their forgotten passwords using the created route definitions. I can "log in" on the login route, but Auth::check()
always returns false in the guest
middleware (Middleware\Authenticate
class).
I've tried the following session drivers without success:
- File
- Redis
- Cookie
- Database
I even tried to revert the users
table primary key to named id
, but that didn't change anything.
Something I noticed: as my user IDs are actually char(36) UUIDs, the database session driver did not save the user_id
properly: it saved the integer characters from the user UUID and then cut off the rest of the value (e.g. users.uuid
3f2358907afafaf
becomes session.user_id
3
), or 0
if the user ID starts with a non-numeric character (a-f
).
I've found a huge amount of questions and threads and search results for this same issue. I tried the things most said would work, but I didn't get it working still:
- I have set the
$user->primaryKey
protected property touuid
(which affects$model->getKey()
and$model->getAuthIdentifier()
too). - I have tried multiple different session drivers with no success.
- I have tried reverting to the
users.id
column name instead ofusers.uuid
, no change. - I have cleared all caches I can think of.
- I have checked that there is no whitespace output before views output (need to dig a bit deeper though in case I missed some files).
The only thing which I have not properly tried yet is to just switch back the auto-incrementing IDs for users (instead of UUIDs). I've tied the UUID concept pretty tight already but I'll see what I can do to solve this issue.
Please do ask for details if I'm missing something in this question.