Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Custom session values on "Remember Me" option for session rebuild #42615

Closed
wants to merge 1 commit into from

Conversation

PaolaRuby
Copy link
Contributor

@PaolaRuby PaolaRuby commented Jun 1, 2022

Example:
Company is a manyToMany relation with User, on login user pick wich company use for signin, on "remember me" laravel rebuild the user session but not the picked company, would be great if session guard can handle that extra id/ids and rebuild the session, also user can be logged on two or more companies at the same time(using different devices, browser, others)

Usage:
On auth.php

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
        'remember_segments' => ['company_id'], // ['company_id', 'year'] more keys
    ],
    // ...
],

So on login user picks the company_id

// request()->all(); request sent to login
[
    'email' => 'email@email.com',
    'password' => 'PASSWORD',
    'company_id' => 1,
    // 'year' => '2021',
    'remember' => 'on',
]

After authentication, company_id will be in session(), and on session rebuild via "Remember Me", company_id returns to session()
Also it's posible use $request->merge() for adding values to request before login

Complement of: #42316
Use case: Teams on spatie/laravel-permission#2075

Open to discussion, could be better

Maybe methods and properties naming needs changes

@PaolaRuby PaolaRuby changed the title Custom session values on "Remember Me" option for session rebuild [9.x] Custom session values on "Remember Me" option for session rebuild Jun 1, 2022
@taylorotwell
Copy link
Member

I suggest just storing the last picked company in the database and pulling it back out on login.

@PaolaRuby
Copy link
Contributor Author

PaolaRuby commented Jun 2, 2022

But when the user login on two devices, and on each device login on different company?

@angeljqv
Copy link
Contributor

angeljqv commented Jun 2, 2022

+1
#42316 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants