Add isAuthenticated method to route_t for user authentication check

This commit is contained in:
Jeppe Bundgaard
2025-11-26 13:29:40 +01:00
parent ecd44a455a
commit 7961217a91
+20
View File
@@ -23,6 +23,26 @@ trait route_t
// Add the routes here
}
/**
* Is authenticated?
* This function returns a boolean indicating if the user is authenticated
* @return bool
*/
public function isAuthenticated(): bool
{
global $response;
try {
$user = (new authentication())->get_user();
// If there is no user, return false
if (!$user) {
return false;
}
return true;
} catch (Exception $e) {
$response->error($e->getMessage(), 400);
}
}
/**
* Require type
* @param mixed $value