mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 09:34:04 +00:00
Add remember column to to the impersonation token (#1101)
This commit is contained in:
parent
dfd39722a7
commit
228c2676f3
3 changed files with 5 additions and 2 deletions
|
|
@ -20,6 +20,7 @@ return new class extends Migration
|
|||
$table->string('token', 128)->primary();
|
||||
$table->string(Tenancy::tenantKeyColumn());
|
||||
$table->string('user_id');
|
||||
$table->boolean('remember');
|
||||
$table->string('auth_guard');
|
||||
$table->string('redirect_url');
|
||||
$table->timestamp('created_at');
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use Stancl\Tenancy\Exceptions\StatefulGuardRequiredException;
|
|||
* @property string $user_id
|
||||
* @property string $auth_guard
|
||||
* @property string $redirect_url
|
||||
* @property bool $remember
|
||||
* @property Carbon $created_at
|
||||
*/
|
||||
class ImpersonationToken extends Model
|
||||
|
|
|
|||
|
|
@ -18,12 +18,13 @@ class UserImpersonation implements Feature
|
|||
|
||||
public function bootstrap(Tenancy $tenancy): void
|
||||
{
|
||||
$tenancy->macro('impersonate', function (Tenant $tenant, string $userId, string $redirectUrl, string $authGuard = null): ImpersonationToken {
|
||||
$tenancy->macro('impersonate', function (Tenant $tenant, string $userId, string $redirectUrl, string|null $authGuard = null, bool $remember = false): ImpersonationToken {
|
||||
return ImpersonationToken::create([
|
||||
Tenancy::tenantKeyColumn() => $tenant->getTenantKey(),
|
||||
'user_id' => $userId,
|
||||
'redirect_url' => $redirectUrl,
|
||||
'auth_guard' => $authGuard,
|
||||
'remember' => $remember,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
|
@ -44,7 +45,7 @@ class UserImpersonation implements Feature
|
|||
|
||||
abort_unless($tokenTenantId === $currentTenantId, 403);
|
||||
|
||||
Auth::guard($token->auth_guard)->loginUsingId($token->user_id);
|
||||
Auth::guard($token->auth_guard)->loginUsingId($token->user_id, $token->remember);
|
||||
|
||||
$token->delete();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue