fix(auth): preserve invite login with database sessions
This commit is contained in:
parent
bec871cf78
commit
c0866d4cb3
2 changed files with 24 additions and 1 deletions
|
|
@ -138,10 +138,11 @@ public function link()
|
||||||
}
|
}
|
||||||
$invitation->delete();
|
$invitation->delete();
|
||||||
|
|
||||||
Auth::login($user);
|
|
||||||
$user->forceFill([
|
$user->forceFill([
|
||||||
'password' => Hash::make(Str::random(64)),
|
'password' => Hash::make(Str::random(64)),
|
||||||
])->save();
|
])->save();
|
||||||
|
|
||||||
|
Auth::login($user);
|
||||||
session(['currentTeam' => $team]);
|
session(['currentTeam' => $team]);
|
||||||
|
|
||||||
return redirect()->route('dashboard');
|
return redirect()->route('dashboard');
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
use Illuminate\Support\Facades\Crypt;
|
use Illuminate\Support\Facades\Crypt;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Once;
|
use Illuminate\Support\Once;
|
||||||
use Visus\Cuid2\Cuid2;
|
use Visus\Cuid2\Cuid2;
|
||||||
|
|
@ -91,6 +92,27 @@ function createInvitationLinkFixture(array $invitationAttributes = []): array
|
||||||
expect(Hash::check($password, $user->password))->toBeFalse();
|
expect(Hash::check($password, $user->password))->toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('keeps the invited user authenticated after rotating the temporary password with database sessions', function () {
|
||||||
|
$this->withMiddleware([CheckForcePasswordReset::class, DecideWhatToDoWithUser::class]);
|
||||||
|
Config::set('session.driver', 'database');
|
||||||
|
|
||||||
|
[$team, $user, $password, $token] = createInvitationLinkFixture();
|
||||||
|
|
||||||
|
$this->get(route('auth.link', ['token' => $token]))
|
||||||
|
->assertRedirect(route('dashboard'));
|
||||||
|
|
||||||
|
expect(DB::table('sessions')->where('user_id', $user->id)->exists())->toBeTrue();
|
||||||
|
|
||||||
|
$this->get(route('dashboard'))
|
||||||
|
->assertRedirect(route('auth.force-password-reset'));
|
||||||
|
|
||||||
|
$this->assertAuthenticatedAs($user);
|
||||||
|
expect($user->teams()->where('team_id', $team->id)->exists())->toBeTrue();
|
||||||
|
|
||||||
|
$user->refresh();
|
||||||
|
expect(Hash::check($password, $user->password))->toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
it('rejects a magic link when the stored invitation token differs', function () {
|
it('rejects a magic link when the stored invitation token differs', function () {
|
||||||
[, $user, , $token, $invitation] = createInvitationLinkFixture();
|
[, $user, , $token, $invitation] = createInvitationLinkFixture();
|
||||||
$differentToken = Crypt::encryptString("{$user->email}@@@{$invitation->uuid}@@@different-password");
|
$differentToken = Crypt::encryptString("{$user->email}@@@{$invitation->uuid}@@@different-password");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue