O3 Framework / getCurrentUser
getCurrentUser():
Observable<Session>
Defined in: packages/framework/esm-api/src/current-user.ts:66
The getCurrentUser function returns an observable that produces zero or more values, over time. It will produce zero values by default if the user is not logged in. And it will provide a first value when the logged in user is fetched from the server. Subsequent values will be produced whenever the user object is updated.
The function accepts an optional opts object with an includeAuthStatus
boolean property that defaults to true. When includeAuthStatus is true,
the entire Session object from the API will be provided. When
includeAuthStatus is false, only the LoggedInUser property of the
response object will be provided.
Observable<Session>
An Observable that produces zero or more values (as described above).
The values produced will be a LoggedInUser object (if includeAuthStatus
is set to false) or a Session object with authentication status
(if includeAuthStatus is set to true or not provided).
import { getCurrentUser } from '@openmrs/esm-api'
const subscription = getCurrentUser().subscribe(
user => console.log(user)
)
subscription.unsubscribe()
getCurrentUser({includeAuthStatus: true}).subscribe(
data => console.log(data.authenticated)
)
Otherwise your code will continue getting updates to the user object even after the UI component is gone from the screen. This is a memory leak and source of bugs.
getCurrentUser(
opts):Observable<Session>
Defined in: packages/framework/esm-api/src/current-user.ts:73
Options for controlling the response format.
true
When true, returns the full Session object
including authentication status.
Observable<Session>
An Observable that produces Session objects.
getCurrentUser(
opts):Observable<LoggedInUser>
Defined in: packages/framework/esm-api/src/current-user.ts:80
Options for controlling the response format.
false
When false, returns only the LoggedInUser object
without the surrounding session information.
Observable<LoggedInUser>
An Observable that produces LoggedInUser objects.