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
nullwhen signed out. - The
Sessionholds 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
Sessionornull. 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');listreturns each account'sid,profile,project,activeandexpired, without tokens.- Accounts are identified by profile reference.
switchandremovethrowOvokAccountErrorwhen the account is missing or its session has expired (switch) or is not saved (remove).removesigns 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
- session API reference: every method and type.
- ovok.realtime, which pauses when the session ends.
- Errors and retries
Last updated on