118 lines
1.5 KiB
TypeScript
118 lines
1.5 KiB
TypeScript
namespace _dali
|
|
{
|
|
|
|
/**
|
|
*/
|
|
let _actions_login : Array<((name ?: (null | string)) => Promise<void>)> = [];
|
|
|
|
|
|
/**
|
|
*/
|
|
let _actions_logout : Array<(() => Promise<void>)> = [];
|
|
|
|
|
|
/**
|
|
*/
|
|
let _is_logged_in : boolean = false;
|
|
|
|
|
|
/**
|
|
*/
|
|
export function listen_login(
|
|
action : ((name ?: (null | string)) => Promise<void>)
|
|
)
|
|
: void
|
|
{
|
|
_actions_login.push(action);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export function listen_logout(
|
|
action : (() => Promise<void>)
|
|
)
|
|
: void
|
|
{
|
|
_actions_logout.push(action);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function notify_login(
|
|
name : (null | string)
|
|
)
|
|
: Promise<void>
|
|
{
|
|
_is_logged_in = true;
|
|
for (const action of _actions_login)
|
|
{
|
|
await action(name);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function notify_logout(
|
|
)
|
|
: Promise<void>
|
|
{
|
|
_is_logged_in = false;
|
|
for (const action of _actions_logout)
|
|
{
|
|
await action();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export function is_logged_in(
|
|
)
|
|
: boolean
|
|
{
|
|
return _is_logged_in;
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function oidc_finish(
|
|
session_key : string
|
|
)
|
|
: Promise<void>
|
|
{
|
|
await _dali.backend.set_session_key(session_key);
|
|
const status = await _dali.backend.status();
|
|
await _dali.notify_login(status.name);
|
|
return Promise.resolve<void>(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function logout(
|
|
)
|
|
: Promise<void>
|
|
{
|
|
try
|
|
{
|
|
await _dali.backend.session_end(
|
|
);
|
|
notify_logout();
|
|
}
|
|
catch (error)
|
|
{
|
|
lib_plankton.log.notice(
|
|
"dali.logout_failed",
|
|
{
|
|
"reason": String(error),
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
}
|