Core\Auth\User auth()
Using our auth() function will give you access to our core authentication class.
<?php route('/foo', function() { // Check if a user is logged in if (auth()->isLoggedIn()) { echo "Hello logged in user!"; } // Check if the user is an admin if (auth()->isAdmin()) { echo "Hello Admin!"; } }); route('/bar', function() { // This will redirect the user if they are not logged in auth()->membersOnly(); }); |
Method | Description | Usage | Returns | |
---|---|---|---|---|
isLoggedIn() | Check if a user is logged in or not. |
| true if logged in, false if not | |
membersOnly() | Redirect a user to the login page if they are not logged in. |
| null | |
isAdmin() | Checks to see if a user is a site Admin |
| true if logged in, false if not |