From 078d1d473fe02a77e3b80e98d347da726fd431bc Mon Sep 17 00:00:00 2001
From: Fred Boniface
Date: Thu, 24 Aug 2023 14:47:48 +0100
Subject: [PATCH] Adjustments to the registration page ref:
https://git.fjla.uk/OwlBoard/backend/issues/39
---
src/lib/libauth.ts | 36 +++++++++++++++++++++-----------
src/routes/more/reg/+page.svelte | 11 ++++++----
2 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/src/lib/libauth.ts b/src/lib/libauth.ts
index 37b213a..a832842 100644
--- a/src/lib/libauth.ts
+++ b/src/lib/libauth.ts
@@ -7,11 +7,16 @@ export interface libauthResponse {
serverAuthCheckResponseCode?: number;
}
+interface uuidCheckRes {
+ uuidValue?: string;
+ uuidPresent?: boolean;
+}
+
export async function checkAuth(): Promise {
let result: libauthResponse = {};
const uuidCheck = await checkUuid();
- result.uuidPresent = uuidCheck.uuidPresent;
- result.uuidValue = uuidCheck.uuidValue;
+ result.uuidPresent = uuidCheck?.uuidPresent;
+ result.uuidValue = uuidCheck?.uuidValue;
const serverCheck = await checkServerAuth();
result.serverAuthCheck = serverCheck.authOk;
@@ -20,35 +25,42 @@ export async function checkAuth(): Promise {
return result
}
-export async function checkUuid() {
+export async function checkUuid(): Promise {
let uuid_value: string = '';
- uuid.subscribe((value => uuid_value = value))
+ const unsubscribe = uuid.subscribe(value => {
+ uuid_value = value;
+ });
+ let res: uuidCheckRes = {
+ uuidValue: uuid_value
+ }
console.log("uuid-value is: ", uuid_value)
if (uuid_value && uuid_value != 'null') {
- return {
+ res = {
uuidPresent: true,
uuidValue: uuid_value,
}
- }
- return {
+ } else {
+ res = {
uuidPresent: false,
- uuidValue: '',
+ uuidValue: uuid_value,
}
-}
+
+}unsubscribe()
+return res;}
export async function checkServerAuth() {
let uuid_value: string = '';
uuid.subscribe((value => uuid_value = value))
- const url = "https://owlboard.info/api/v2/auth/check"
+ const url = "https://owlboard.info/api/v2/user/checkAuth"
const options = {
method: 'GET',
headers: {
uuid: uuid_value,
}
- };
+ };
const res = await fetch(url, options)
let ok: boolean;
- if (res.status === 200) {
+ if (res.status !== 401) {
ok = true;
} else {
ok = false;
diff --git a/src/routes/more/reg/+page.svelte b/src/routes/more/reg/+page.svelte
index 0dee6c3..0bc1d98 100644
--- a/src/routes/more/reg/+page.svelte
+++ b/src/routes/more/reg/+page.svelte
@@ -9,7 +9,7 @@
const title = 'Register';
let state = 'unreg';
- let isLoading = false;
+ let isLoading = true;
let inputValue = '';
function handleInput(event) {
@@ -46,14 +46,16 @@
} else if (auth.uuidPresent === true) {
state = 'reg';
}
+ isLoading = false;
});
-{#if isLoading}
-
-{/if}
+
+{#if isLoading}
+
+{:else}
{#if state == 'unreg'}
The staff version of OwlBoard offers several extra features:
@@ -92,6 +94,7 @@
browser.
{/if}
+{/if}