openmrs-esm-core

O3 Framework / getSessionStore

Function: getSessionStore()

getSessionStore(): StoreApi<SessionStore>

Defined in: packages/framework/esm-api/src/current-user.ts:123

Returns the global session store containing the current user’s session information. If the session data is stale (older than 1 minute) or not yet loaded, this function will trigger a refetch of the current user’s session.

Returns

StoreApi<SessionStore>

The global session store that can be subscribed to for session updates.

Example

import { getSessionStore } from '@openmrs/esm-api';
const store = getSessionStore();
const unsubscribe = store.subscribe((state) => {
  if (state.loaded) {
    console.log('Session:', state.session);
  }
});