aboutsummaryrefslogtreecommitdiffstats
path: root/code/app/src/lib/session.ts
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-10-25 11:51:37 +0200
committerivarlovlie <git@ivarlovlie.no>2022-10-25 11:51:37 +0200
commit0005595703b2f3f7083ce4ba19bf5770057c75bd (patch)
tree193a897f61a9a5e566961601de4cf42ae85984a0 /code/app/src/lib/session.ts
parent585c5c8537eb21dfc9f16108548e63d9ced3d971 (diff)
downloadgreatoffice-0005595703b2f3f7083ce4ba19bf5770057c75bd.tar.xz
greatoffice-0005595703b2f3f7083ce4ba19bf5770057c75bd.zip
.
Diffstat (limited to 'code/app/src/lib/session.ts')
-rw-r--r--code/app/src/lib/session.ts16
1 files changed, 8 insertions, 8 deletions
diff --git a/code/app/src/lib/session.ts b/code/app/src/lib/session.ts
index 7cd5fcf..48dcc50 100644
--- a/code/app/src/lib/session.ts
+++ b/code/app/src/lib/session.ts
@@ -1,13 +1,13 @@
import { log_error, log_info } from "$lib/logger";
import { Temporal } from "temporal-polyfill";
-import { get_profile_for_active_check, logout } from "./api/user";
+import { http_account } from "$lib/api/account";
import { is_guid, session_storage_get_json, session_storage_set_json } from "./helpers";
import { SECONDS_BETWEEN_SESSION_CHECK, StorageKeys } from "./configuration";
-import type { ISession } from "$lib/models/internal/ISession";
+import type { Session } from "$lib/models/internal/ISession";
export async function is_active(forceRefresh: boolean = false): Promise<boolean> {
const nowEpoch = Temporal.Now.instant().epochSeconds;
- const data = session_storage_get_json(StorageKeys.session) as ISession;
+ const data = session_storage_get_json(StorageKeys.session) as Session;
const expiryEpoch = data?.lastChecked + SECONDS_BETWEEN_SESSION_CHECK;
const lastCheckIsStaleOrNone = !is_guid(data?.profile?.id) || (expiryEpoch < nowEpoch);
if (forceRefresh || lastCheckIsStaleOrNone) {
@@ -23,7 +23,7 @@ export async function is_active(forceRefresh: boolean = false): Promise<boolean>
}
export async function end_session(cb: Function): Promise<void> {
- await logout();
+ await http_account.logout_async();
clear_session_data();
cb();
}
@@ -31,14 +31,14 @@ export async function end_session(cb: Function): Promise<void> {
async function call_api(): Promise<boolean> {
log_info("Getting profile data while checking session state");
try {
- const response = await get_profile_for_active_check();
+ const response = await http_account.get_profile_async(true);
if (response.ok) {
const userData = await response.data;
if (is_guid(userData.id) && userData.username) {
const session = {
profile: userData,
lastChecked: Temporal.Now.instant().epochSeconds
- } as ISession;
+ } as Session;
session_storage_set_json(StorageKeys.session, session);
log_info("Successfully got profile data while checking session state");
return true;
@@ -64,6 +64,6 @@ export function clear_session_data() {
log_info("Cleared session data.");
}
-export function get_session_data(): ISession {
- return session_storage_get_json(StorageKeys.session) as ISession;
+export function get_session_data(): Session {
+ return session_storage_get_json(StorageKeys.session) as Session;
}