Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share auth sessions across sub domains with multiple Laravel 5 project

Current system:

  • Have two Laravel project: 5.2 and 5.3
  • Using sub domain on local: control.foo-bar.dev (Laravel 5.2) and service.foo-bar.dev (Laravel 5.3)

.ENV setting:

APP_KEY=base64:tRpczdAlZ3jZ5VbP4sBU6BJcltftB5pBFpOuHbh/pq4=

SESSION_DRIVER=cookie

SESSION_DOMAIN=foo-bar.dev

config/app.php setting:

'cookie' => 'laravel_session'

Now I can login from Laravel 5.2 and can use that cookies for Laravel 5.3 but can't opposite.

I had try to change SESSION_DRIVER=cookie => database but get same result.

like image 211
Quynh Nguyen Avatar asked Jan 14 '17 02:01

Quynh Nguyen


1 Answers

With this situation, I am pretty sure you have to prepend the dot on your cookie domain. eg:

SESSION_DOMAIN=.foo-bar.dev

Give it a go, see if it works.

Edit: Also, my 5.2 has the session cookie domain as null so make sure it is set to 'domain' => env('SESSION_DOMAIN', null), in your config/session.php

like image 131
CUGreen Avatar answered Sep 28 '22 00:09

CUGreen