Bristol SU Support Package
UserApiAuthentication.php
Go to the documentation of this file.
1 <?php
2 
3 namespace BristolSU\Support\User;
4 
6 use Illuminate\Contracts\Auth\Factory as AuthFactory;
7 
12 {
18  private $auth;
19 
23  public function __construct(AuthFactory $auth)
24  {
25  $this->auth = $auth;
26  }
27 
33  public function getUser(): ?User
34  {
35  if ($this->auth->guard('api')->check()) {
36  return $this->auth->guard('api')->user();
37  }
38  return null;
39  }
40 
48  public function setUser(User $user)
49  {
50  throw new \Exception('Cannot set an API user');
51  }
52 
59  public function logout(): void
60  {
61  throw new \Exception('Cannot log out an API user');
62  }
63 }