Add isAuthenticated method to route_t for user authentication check
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user