October CMS how to get backend user ?

If your developing backend plugins in OctoberCMS at some point you require backend user details.

There are many scenarios like authoring post or tho ownership of record you must need backend user. below code snippet show you how to get backend user.

How to check backend user is logged in or not

use BackendAuth;

// returns true if backend user is signed in.
$loggedIn = BackendAuth::check();

Above code snippet let you know that if backend user is signed in or not.

If user is signed in then we can get user details by below code snippet.

How to get backend user

use BackendAuth;

$loggedIn = BackendAuth::check();

// if user signed in then do this other wise else part
if($loggedIn) {
    // returns the signed in user
    $backendUser = BackendAuth::getUser();    
}
else {
    // user is not signed in
}

By using above code snippets you can easily identify if backend user is signed in or not and get user's details for further usage in your plugin.

js interview questions