import { uuid } from "./stores/uuid" export interface libauthResponse { uuidPresent?: boolean; serverAuthCheck?: boolean; uuidValue?: string; serverAuthCheckResponseCode?: number; } export async function checkAuth(): Promise { let result: libauthResponse = {}; const uuidCheck = await checkUuid(); result.uuidPresent = uuidCheck.uuidPresent; result.uuidValue = uuidCheck.uuidValue; const serverCheck = await checkServerAuth(); result.serverAuthCheck = serverCheck.authOk; result.serverAuthCheckResponseCode = serverCheck.status; return result } export async function checkUuid() { let uuid_value: string = ''; uuid.subscribe((value => uuid_value = value)) console.log("uuid-value is: ", uuid_value) if (uuid_value && uuid_value != 'null') { return { uuidPresent: true, uuidValue: uuid_value, } } return { uuidPresent: false, uuidValue: '', } } export async function checkServerAuth() { let uuid_value: string = ''; uuid.subscribe((value => uuid_value = value)) const url = "https://owlboard.info/api/v2/auth/check" const options = { method: 'GET', headers: { uuid: uuid_value, } }; const res = await fetch(url, options) let ok: boolean; if (res.status === 200) { ok = true; } else { ok = false; } return { authOk: ok, status: res.status, } }