diff --git a/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte b/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte
index ad1be730..f5e98f95 100644
--- a/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte
+++ b/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte
@@ -2,12 +2,9 @@
import Canvas from "../pieces/Canvas.svelte";
import { push } from "svelte-spa-router";
import { onMount } from 'svelte';
- import { loginStatus } from '../stores/loginStatusStore.js';
import { userStore, userLogout } from '../stores/loginStatusStore.js';
- // go over agian in detail to make sure this actually does what you want
- // it needs some work, seems confused a lot of the time...
onMount(async () => {
console.log('SplashPage testing if logged in')
// let user = await fetch('http://transcendance:8080/api/v2/user')
@@ -43,9 +40,18 @@
// }
+ // for some reason unlike in ProfileDisplay here the user is never undefined...
+ // ok i think it's because here i declare the user in the call whereas in ProfileDisplay i declare user before...
+ // if (user !== undefined) {
+ // console.log('user not undefined')
+ // }
+ // else
+ // console.log('user undefined')
+
// to clean up local storage... as a precaution
// this condition isn't good enough...
- if (user && user.statusCode && user.statusCode === 403) {
+ // if (user && user.statusCode && user.statusCode === 403) {
+ if (user === undefined) {
console.log('on mount no user, returned status code 403 so logging out of userStore')
userLogout(); // which i think should delete any previous local storage
}
diff --git a/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte b/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte
index 8fc8d500..5d1cb717 100644
--- a/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte
+++ b/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte
@@ -1,7 +1,6 @@
diff --git a/srcs/requirements/svelte/api_front/src/pieces/Header.svelte b/srcs/requirements/svelte/api_front/src/pieces/Header.svelte
index e2cc2c5f..237a7565 100644
--- a/srcs/requirements/svelte/api_front/src/pieces/Header.svelte
+++ b/srcs/requirements/svelte/api_front/src/pieces/Header.svelte
@@ -1,7 +1,6 @@
diff --git a/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js b/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js
index 98a32894..d89a9d57 100644
--- a/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js
+++ b/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js
@@ -1,47 +1,12 @@
import { writable } from "svelte/store";
-function createLoginStatus() {
- const { subscribe, update } = writable({
- fortyTwo: false,
- tfa: false,
- });
-
- function toggle42() {
- update( (old) => ({...old, fortyTwo: !old.fortyTwo}) );
- };
-
- function toggleTFA() {
- update( (old) => ({...old, tfa: !old.tfa}) );
- };
-
- function allTrue() {
- update( (old) => ({fortyTwo: true, tfa: true}) );
- }
-
- function allFalse() {
- update( (old) => ({fortyTwo: false, tfa: false}) );
- }
-
- function isLogged() {
- // return (l) => {l.fortyTwo && l.tfa};
- // return self.fortyTwo && self.tfa;
- // return fortyTwo && tfa;
- return (old) => (old.fortyTwo && old.tfa);
- };
-
- return { subscribe, update, toggle42, toggleTFA, allTrue, allFalse, isLogged };
-}
-
-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');
+// turns out a simple store is actually the easiest :)
export const userStore = 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