O3 Framework / getCurrentUser
getCurrentUser():
Promise<Session>
Defined in: packages/framework/esm-api/src/current-user.ts:105
The getCurrentUser function returns a Promise that resolves once with the current user’s session. If the session hasn’t been loaded, was loaded more than a minute ago, or is in the middle of being refetched, the Promise waits for the fetch in question rather than resolving with data that may be out of date. The session it resolves with is therefore never more than a minute old, unless that fetch fails, in which case it resolves with the last session that loaded.
The function accepts an optional opts object with an includeAuthStatus boolean
property that defaults to true. When true, the entire Session object
from the API is provided. When false, only the LoggedInUser property of
the response is provided.
To react to subsequent session changes (login, logout, user-property updates),
use getSessionStore (getState() / subscribe()) or the useSession
React hook rather than calling this repeatedly.
Promise<Session>
A Promise resolving to a LoggedInUser object (if includeAuthStatus
is false) or a Session object (if includeAuthStatus is true or not
provided).
import { getCurrentUser } from '@openmrs/esm-api'
const session = await getCurrentUser({ includeAuthStatus: true })
console.log(session.authenticated)
getCurrentUser(
opts):Promise<Session>
Defined in: packages/framework/esm-api/src/current-user.ts:112
Options for controlling the response format.
true
When true, resolves with the full Session object
including authentication status.
Promise<Session>
A Promise resolving to a Session object.
getCurrentUser(
opts):Promise<LoggedInUser>
Defined in: packages/framework/esm-api/src/current-user.ts:119
Options for controlling the response format.
false
When false, resolves with only the LoggedInUser object
without the surrounding session information.
Promise<LoggedInUser>
A Promise resolving to a LoggedInUser object.