Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel actingAs guest

Laravel provides a way to authenticate a given user during HTTP testing with

$this->actingAs($user);

Is there a way to unauthenticate that $user within the same test?

like image 661
Erich Avatar asked Jan 27 '26 11:01

Erich


1 Answers

Yes, you can unauthenticate using this:

Auth::logout();

https://laravel.com/docs/7.x/authentication#logging-out

Warning: above does far more than just forgetting (acting as if the login did not happen), for example, when using JWT above should invalidate token.

like image 95
justinas.linkevicius Avatar answered Jan 29 '26 10:01

justinas.linkevicius