so far this works, in the middle of adding a new store that connects to local storage
This commit is contained in:
@@ -11,6 +11,8 @@
|
|||||||
replace('/unauthorized-access');
|
replace('/unauthorized-access');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// this might be the part where we get rid of localstorage when the app is quit?
|
||||||
|
// onDestroy()
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -43,11 +43,6 @@
|
|||||||
loginStatus.allFalse()
|
loginStatus.allFalse()
|
||||||
};
|
};
|
||||||
|
|
||||||
const toProfile = () => {
|
|
||||||
push('/profile');
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
@@ -61,10 +56,19 @@
|
|||||||
{#if ($loginStatus.fortyTwo && $loginStatus.tfa) === false}
|
{#if ($loginStatus.fortyTwo && $loginStatus.tfa) === false}
|
||||||
<div on:click={login}>Login</div>
|
<div on:click={login}>Login</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div on:click={toProfile}>Profile</div>
|
<div on:click={ () => (push('/profile')) }>Profile</div>
|
||||||
<div on:click={logout}>Logout</div>
|
<div on:click={logout}>Logout</div>
|
||||||
{/if}
|
{/if}
|
||||||
</nav>
|
</nav>
|
||||||
|
<!-- <nav> -->
|
||||||
|
<!-- seems redundant but let's give it a try -->
|
||||||
|
<!-- {#if $store !== null}
|
||||||
|
<div on:click={ () => (push('/profile')) }>Profile</div>
|
||||||
|
<div on:click={logout}>Logout</div>
|
||||||
|
{:else}
|
||||||
|
<div on:click={login}>Login</div>
|
||||||
|
{/if}
|
||||||
|
</nav> -->
|
||||||
<h2>
|
<h2>
|
||||||
<div>Welcome to</div>
|
<div>Welcome to</div>
|
||||||
<div>Potato Pong</div>
|
<div>Potato Pong</div>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<div class="tabs">
|
<div class="tabs">
|
||||||
<!-- creates a list, can be done other ways -->
|
<!-- creates a list, can be done other ways -->
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
@@ -33,3 +33,28 @@ function createLoginStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const loginStatus = 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));
|
||||||
|
// }
|
||||||
Reference in New Issue
Block a user