Namespaces

ovok.session

Read the current session, follow session changes and switch between saved accounts.

  • Stable unknown
  • Release candidate since 0.4.49-rc.4
  • Development since 0.4.49-dev.517+4645a0a

ovok.session reports who is signed in and keeps the accounts saved on this device. Sign-in itself is in ovok.auth. A machine client has no user session: current returns null and saved accounts throw OvokConfigError.

Read the current session

const session = await ovok.session.current();

if (session === null) {
  // signed out
} else {
  console.log(session.profile.reference, session.project.reference);
}
  • It returns the restored session, or null when signed out.
  • The Session holds the access token, its expiry, the project and the profile.

Follow session changes

const stop = ovok.session.onChange((session) => {
  console.log(session?.profile.reference ?? 'signed out');
});

stop();
  • The listener fires when a session starts, changes or ends, including when a refused refresh token signs the user out.
  • It receives the active Session or null. The returned function stops listening.

Switch between saved accounts

The client saves a private session for each signed-in profile in the configured storage.

const accounts = await ovok.session.savedAccounts.list();

await ovok.session.savedAccounts.switch('Patient/123');
await ovok.session.savedAccounts.remove('Patient/123');
  • list returns each account's id, profile, project, active and expired, without tokens.
  • Accounts are identified by profile reference.
  • switch and remove throw OvokAccountError when the account is missing or its session has expired (switch) or is not saved (remove).
  • remove signs the account out on the server unless it has expired, then forgets it. Removing the active account switches to the next saved one, when there is one.

Reference

Last updated on

On this page