The
auth
function returns an authenticator instance. You may use it as an alternative to the Auth
facade:<?php $user = auth()->user();
<?php {
public function protect()
{
if (auth()->check()) {
return;
}
<?php public function current(): ?User
{
if (! $user = auth()->user()) {
return null;
}
<?php public function logout()
{
auth()->logout();
abort(redirect($this->params->get('redirect', '/'), $this->params->get('response', 302)));
}
<?php public function all()
{
if (auth()->guest()) {
return [];
}
<?php 'response_code' => 200,
'logged_in' => $loggedIn = auth()->check(),
'logged_out' => ! $loggedIn,
<?php ])
->assertLocation('/');
$this->assertFalse(auth()->check());
$output = $this->tag(<<<'EOT'
{{ user:login_form }}
<?php public function it_will_log_user_in_and_render_success()
{
$this->assertFalse(auth()->check());
User::make()
->email('san@holo.com')
<?php ])
->assertLocation('/');
$this->assertTrue(auth()->check());
$output = $this->tag(<<<'EOT'
{{ user:login_form }}
<?php public function it_will_log_user_in_and_follow_custom_redirect_with_success()
{
$this->assertFalse(auth()->check());
User::make()
->email('san@holo.com')
<?php ])
->assertLocation('/login-successful');
$this->assertTrue(auth()->check());
$output = $this->tag(<<<'EOT'
{{ user:login_form }}
<?php public function it_wont_log_user_in_and_follow_custom_error_redirect_with_errors()
{
$this->assertFalse(auth()->check());
User::make()
->email('san@holo.com')
<?php ])
->assertLocation('/login-error');
$this->assertFalse(auth()->check());
$output = $this->tag(<<<'EOT'
{{ user:login_form }}
<?php public function it_wont_register_user_and_renders_errors()
{
$this->assertNull(User::findByEmail('san@holo.com'));
$this->assertFalse(auth()->check());
$this
->post('/!/auth/register', [])
<?php ->assertLocation('/');
$this->assertNull(User::findByEmail('san@holo.com'));
$this->assertFalse(auth()->check());
$output = $this->tag(<<<'EOT'
{{ user:register_form }}
<?php $this->useCustomBlueprint();
$this->assertNull(User::findByEmail('san@holo.com'));
$this->assertFalse(auth()->check());
$this
->post('/!/auth/register', [