## cockpit.js: User Session cockpit.js: User Session — User information and login session state |

## cockpit.logout()

    cockpit.logout([reload])

Logout of Cockpit. Unless `reload` is `false` this will also cause the page to be reloaded, so that the user can see the logged out state.

## cockpit.user()

    var promise = cockpit.user();
    promise.then(user => { ... });

This object contains information about the user that's currently logged into cockpit. The following fields are defined:

`"id"` | This is unix user id.
`"gid"` | This is unix user group id.
`"name"` | This is the unix user name like `"root"`.
`"full_name"` | This is a readable name for the user.
`"groups"` | This is an array of group names to which the user belongs. Since version 318, the first item in this list is the primary group.
`"home"` | This is user's home directory.
`"shell"` | This is unix user shell.

Returns a promise that completes once the user information is available.

### Warning

`cockpit.user()` is soft-deprecated since Cockpit 336, if your page does not need to maintain compatibility with older Cockpit versions you can usecockpit.info to obtain the user information.

## Permission lookup

Cockpit provides a mechanism for checking if the current user satisfies a given criteria. This is meant for updating UI elements based on what actions the user can perform. It is not an access control mechanism.

### cockpit.permission()

    permission = cockpit.permission([options])

Create a new permission object to check if the current user has a particular permission specified by `options`:

`admin: true` | True if the session has superuser privileges, i.e. can run channels as root with `{ superuser: "require" }`.
`group:` name | True if the currently logged user is a member of group name.

The permission result is always true for the "root" user. When `options` is not given, check if the current user is root.

### permission.allowed

A boolean value which indicates if the permission is allowed or not. This will be `null` if the permission is unknown, or there was an error checking the permission or the permission data has not yet loaded. This property will update asynchronously and if you wish to be notified of changes connect to the permission.onchanged event.

### permission.onchanged

    permission.addEventListener("changed", function() { ... })

This event is fired when the permission changes. In particular the permission.allowed property.

### permission.close()

    permission.close()

Closes the permission object and tears down any registered callbacks and dbus subscriptions.