LoginLogout

This commit is contained in:
2024-07-21 15:49:43 +02:00
parent 132e8790a3
commit 8d91e805dd
10 changed files with 293 additions and 51 deletions
+10 -3
View File
@@ -2,8 +2,10 @@
namespace Khofmann\Auth;
use Exception;
use Pecee\Http\Middleware\IMiddleware;
use Pecee\Http\Request;
use Khofmann\Models\User\User;
class Auth implements IMiddleware
{
@@ -11,10 +13,15 @@ class Auth implements IMiddleware
{
$token = $request->getHeader("token");
//TODO: Auth user with token
// No token
if ($token === null) {
response()->httpCode(401)->json(["message" => "Not Authorized"]);
}
// If authentication failed
if ($request->token === null) {
try {
User::getByToken($token);
} catch (Exception $err) {
// No user with this token exists
response()->httpCode(401)->json(["message" => "Not Authorized"]);
}
}