From 92acf36962e282532a910ec214f39e417675ca07 Mon Sep 17 00:00:00 2001 From: Me Date: Thu, 1 Dec 2022 21:02:43 +0100 Subject: [PATCH] so far this works, in the middle of adding a new store that connects to local storage --- .../svelte/api_front/src/App.svelte | 2 ++ .../api_front/src/pages/SplashPage.svelte | 16 +++++++----- .../svelte/api_front/src/pieces/Tabs.svelte | 1 + .../api_front/src/stores/loginStatusStore.js | 25 +++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/srcs/requirements/svelte/api_front/src/App.svelte b/srcs/requirements/svelte/api_front/src/App.svelte index c51dba57..bb5ca6eb 100644 --- a/srcs/requirements/svelte/api_front/src/App.svelte +++ b/srcs/requirements/svelte/api_front/src/App.svelte @@ -11,6 +11,8 @@ replace('/unauthorized-access'); }; + // this might be the part where we get rid of localstorage when the app is quit? + // onDestroy() diff --git a/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte b/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte index 705bc77c..64566078 100644 --- a/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte +++ b/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte @@ -43,11 +43,6 @@ loginStatus.allFalse() }; - const toProfile = () => { - push('/profile'); - }; - - @@ -61,10 +56,19 @@ {#if ($loginStatus.fortyTwo && $loginStatus.tfa) === false}
Login
{:else} -
Profile
+
(push('/profile')) }>Profile
Logout
{/if} + + +

Welcome to
Potato Pong
diff --git a/srcs/requirements/svelte/api_front/src/pieces/Tabs.svelte b/srcs/requirements/svelte/api_front/src/pieces/Tabs.svelte index 1e558065..5d33f123 100644 --- a/srcs/requirements/svelte/api_front/src/pieces/Tabs.svelte +++ b/srcs/requirements/svelte/api_front/src/pieces/Tabs.svelte @@ -7,6 +7,7 @@ +
    diff --git a/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js b/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js index 4b56dacc..8ea5a8a7 100644 --- a/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js +++ b/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js @@ -33,3 +33,28 @@ function createLoginStatus() { } export const loginStatus = createLoginStatus(); + + +// an alternative way of doing things where i have a svelte store connected to localStorage + +// do in need to adapt this to work with 2fa? + + +let _user = localStorage.getItem('42User'); + +export const store = writable(_user ? JSON.parse(_user) : null); // we start with no user, but go get one if one exists + +// ok so this will happen no matter what, basically we are telling it what to do if the store containing the user changes +store.subscribe((value) => { + if (value) localStorage.setItem('42User', JSON.stringify(value)); + else localStorage.removeItem('42User'); // for logout +}); + + +export const logout = () => store.set(null); + +// ok this is the part where i need to use our API rather than Auth +// export async function signUp(username, password, email) { +// return Auth.signUp(username, password, email) +// .then((data) => void store.set(data)); +// } \ No newline at end of file