user237329
user237329

Reputation: 819

Disable refreshRememberToken in Laravel 5.2

In laravel 5.2 when I do \Auth::logout() there is a refreshRememberToken call that tries to regenerate a token (to be saved in database).

Question: How can I disable this feature?

I do not want this feature (it generates a lot of error now due the lack of the column & etc)

Upvotes: 1

Views: 226

Answers (2)

user237329
user237329

Reputation: 819

For now I used the following dirty trick:

On User model I added this method

function setRememberTokenAttribute($value)
{
    return;
}

This looks to me to be more an work-around and not a solution

Upvotes: 1

Hilmi Erdem KEREN
Hilmi Erdem KEREN

Reputation: 2009

It looks like there is no configurable way of doing this. (I am not sure, just casted an eye on the code.)

However you can extend&override the logout method of Guard and don't call the refreshRememberToken method (or extend&override refreshRememberToken method and just return true from refreshRememberToken)

If you don't want to extend guard, you can also create a customised user provider which will implement Illuminate\Contracts\Auth\UserProvider.

In the interface you must implement Illuminate\Contracts\Auth\UserProvider there are two method signatures you should bypass:

/**
 * Retrieve a user by their unique identifier and "remember me" token.
 *
 * @param  mixed   $identifier
 * @param  string  $token
 * @return \Illuminate\Contracts\Auth\Authenticatable|null
 */
public function retrieveByToken($identifier, $token);

/**
 * Update the "remember me" token for the given user in storage.
 *
 * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
 * @param  string  $token
 * @return void
 */
public function updateRememberToken(Authenticatable $user, $token);

After bypassing; you have extend auth Auth::provider('customimplementation') and then change the driver key of the auth configuration:

'providers' => [
    'users' => [
        'driver' => 'customimplementation',
    ],
],

If you need more information about extending auth drivers or guard, follow https://laravel.com/docs/5.2/authentication#adding-custom-guards https://laravel.com/docs/5.2/authentication#adding-custom-user-providers

Upvotes: 1

Related Questions