everything still works, and i cleaned more stuff up, better flow, disabled features that i need imput to make work
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
import { loginStatus } from './stores/loginStatusStore.js';
|
import { loginStatus } from './stores/loginStatusStore.js';
|
||||||
|
|
||||||
// go over agian in detail to make sure this actually does what you want
|
// 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 () => {
|
onMount(async () => {
|
||||||
console.log('SplashPage testing if logged in')
|
console.log('SplashPage testing if logged in')
|
||||||
let user = await fetch('http://transcendance:8080/api/v2/user')
|
let user = await fetch('http://transcendance:8080/api/v2/user')
|
||||||
|
|||||||
@@ -1,23 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|
||||||
// import { primaryRoutes } from "../routes.js";
|
|
||||||
import { push } from "svelte-spa-router";
|
import { push } from "svelte-spa-router";
|
||||||
|
import { location } from 'svelte-spa-router';
|
||||||
import { loginStatus } from "../stores/loginStatusStore.js";
|
import { loginStatus } from "../stores/loginStatusStore.js";
|
||||||
|
|
||||||
import {location} from 'svelte-spa-router';
|
|
||||||
// this could be how i change the header based on which Route it's in
|
|
||||||
import active from 'svelte-spa-router/active'
|
import active from 'svelte-spa-router/active'
|
||||||
// or i could leave them all and not display if they're active?
|
// or i could leave them all and not display if they're active?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let handleClickHome = () => {
|
|
||||||
// dispatch('clickedHome');
|
|
||||||
// profile?
|
|
||||||
console.log('clicked home')
|
|
||||||
push('/profile');
|
|
||||||
};
|
|
||||||
|
|
||||||
let handleClickLogout = async () => {
|
let handleClickLogout = async () => {
|
||||||
// dispatch('clickedLogout');
|
// dispatch('clickedLogout');
|
||||||
await fetch('http://transcendance:8080/api/v2/auth/logout', {
|
await fetch('http://transcendance:8080/api/v2/auth/logout', {
|
||||||
@@ -29,70 +18,28 @@
|
|||||||
push('/');
|
push('/');
|
||||||
};
|
};
|
||||||
|
|
||||||
// TMP for testing Fetch
|
|
||||||
|
|
||||||
// let response;
|
|
||||||
let promise;
|
|
||||||
|
|
||||||
let handleClickFetch = async () => {
|
|
||||||
// await fetch('http://transcendance:8080/api/v2/user')
|
|
||||||
// .then((res) => {response = res})
|
|
||||||
// let {data} = await fetch('http://transcendance:8080/api/v2/user');
|
|
||||||
promise = await fetch('http://transcendance:8080/api/v2/user')
|
|
||||||
.then( (x) => x.json() );
|
|
||||||
// there's a () after the .json, duh!!!!
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- What if i could query what the current URL is and based on that change the button names in the NAV! -->
|
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<img src="/img/potato_logo.png" alt="Potato Pong Logo" on:click={handleClickHome}>
|
<img src="/img/potato_logo.png" alt="Potato Pong Logo" on:click={() => (push('/'))}>
|
||||||
<!-- {#if currentType === 'home'} -->
|
<!-- /profile or / ? not sure -->
|
||||||
<h1>Potato Pong</h1>
|
<h1>Potato Pong</h1>
|
||||||
<!-- {/if} -->
|
|
||||||
<nav>
|
<nav>
|
||||||
<!-- TMP for testing Fetch -->
|
{#if $location !== '/profile'}
|
||||||
{#if $location === '/profile/fetch'}
|
<button on:click={() => (push('/profile'))}>My Profile</button>
|
||||||
<button on:click={handleClickFetch}>Do a Fetch</button>
|
{:else if $location === '/profile'}
|
||||||
|
<button on:click={() => (push('/profile/settings'))}>Settings</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- <a href=""></a> -->
|
<!-- <button on:click={() => (push('/stream'))}>Stream</button> -->
|
||||||
<!-- i might change these to links rather than buttons, i kinda hate the buttons -->
|
<!-- <button on:click={() => (push('/chat'))}>Chat</button> -->
|
||||||
<!-- maybe just p or div actually idk -->
|
|
||||||
<!-- {#if userpage === 'display'} -->
|
|
||||||
<button>My Stats</button>
|
|
||||||
<!-- {:else if userpage === 'settings'} -->
|
|
||||||
<!-- {:else} -->
|
|
||||||
<!-- button idk something about -->
|
|
||||||
<button>Stream</button>
|
|
||||||
<button on:click={handleClickLogout}>Log Out</button>
|
<button on:click={handleClickLogout}>Log Out</button>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- TMP for testing fetch -->
|
|
||||||
|
|
||||||
{#if $location === '/profile/fetch'}
|
|
||||||
<p>Made it to /fetch</p>
|
|
||||||
<!-- {#if response != undefined} -->
|
|
||||||
<!-- <p>{response}</p> -->
|
|
||||||
<!-- <p>{response.json.username}</p> -->
|
|
||||||
<!-- <p>{response.json}</p> -->
|
|
||||||
<!-- {/if} -->
|
|
||||||
{#if promise !== undefined}
|
|
||||||
<!-- <p>{promise}}</p> -->
|
|
||||||
<!-- <p>{JSON.stringify(promise, null, 2)}</p> -->
|
|
||||||
<p>{promise.username}</p>
|
|
||||||
{/if}
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,55 +11,85 @@ import { get } from 'svelte/store';
|
|||||||
// "/article/:title": Article, // this is how you would do parameters!
|
// "/article/:title": Article, // this is how you would do parameters!
|
||||||
// "/": LoginPage,
|
// "/": LoginPage,
|
||||||
|
|
||||||
|
// TMP not using this cuz need to work out how to authentical both 42 and 2FA from the backend
|
||||||
|
|
||||||
|
// export const primaryRoutes = {
|
||||||
|
// '/': SplashPage,
|
||||||
|
// // '/2fa': TwoFactorAuthentication,
|
||||||
|
// '/2fa': wrap({
|
||||||
|
// component: TwoFactorAuthentication,
|
||||||
|
// conditions: [
|
||||||
|
// (detail) => {
|
||||||
|
// // let loggedIn;
|
||||||
|
// // loginStatus.subscribe(value => {
|
||||||
|
// // loggedIn = value;
|
||||||
|
// // });
|
||||||
|
|
||||||
|
// const { fortyTwo, tfa } = get(loginStatus);
|
||||||
|
|
||||||
|
// console.log('condition in /2fa');
|
||||||
|
// // return (loginStatus.fortyTwo && loginStatus.tfa);
|
||||||
|
// // console.log($loginStatus.fortyTwo)
|
||||||
|
// console.log(fortyTwo);
|
||||||
|
// console.log(tfa);
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }),
|
||||||
|
// '/profile': wrap({
|
||||||
|
// component: ProfilePage,
|
||||||
|
// conditions: [
|
||||||
|
// (detail) => {
|
||||||
|
// const { fortyTwo, tfa } = get(loginStatus);
|
||||||
|
// // console.log(fortyTwo);
|
||||||
|
// // console.log(tfa);
|
||||||
|
// // return true;
|
||||||
|
// return (fortyTwo && tfa);
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }),
|
||||||
|
// '/profile/*': wrap({
|
||||||
|
// component: ProfilePage,
|
||||||
|
// conditions: [
|
||||||
|
// (detail) => {
|
||||||
|
// const { fortyTwo, tfa } = get(loginStatus);
|
||||||
|
// // console.log(fortyTwo);
|
||||||
|
// // console.log(tfa);
|
||||||
|
// // return true;
|
||||||
|
// return (fortyTwo && tfa);
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }),
|
||||||
|
// and example
|
||||||
|
// '/profile': wrap({
|
||||||
|
// // Use a dynamically-loaded component for this
|
||||||
|
// asyncComponent: () => import('./ProfilePage.svelte'),
|
||||||
|
// // Adding one pre-condition that's an async function
|
||||||
|
// conditions: [
|
||||||
|
// async (detail) => {
|
||||||
|
// // Make a network request, which are async operations
|
||||||
|
// const response = await fetch('http://transcendance:8080/api/v2/user')
|
||||||
|
// const data = await response.json()
|
||||||
|
// // Return true to continue loading the component, or false otherwise
|
||||||
|
// if (data.isAdmin) {
|
||||||
|
// return true
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// return false
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }),
|
||||||
|
// '/unauthorized-access': UnauthorizedAccessPage,
|
||||||
|
// '*': NotFound
|
||||||
|
// };
|
||||||
|
|
||||||
export const primaryRoutes = {
|
export const primaryRoutes = {
|
||||||
'/': SplashPage,
|
"/": SplashPage,
|
||||||
// '/2fa': TwoFactorAuthentication,
|
"/profile": ProfilePage,
|
||||||
'/2fa': wrap({
|
"/profile/*": ProfilePage,
|
||||||
component: TwoFactorAuthentication,
|
|
||||||
conditions: [
|
|
||||||
(detail) => {
|
|
||||||
// let loggedIn;
|
|
||||||
// loginStatus.subscribe(value => {
|
|
||||||
// loggedIn = value;
|
|
||||||
// });
|
|
||||||
|
|
||||||
const { fortyTwo, tfa } = get(loginStatus);
|
|
||||||
|
|
||||||
console.log('condition in /2fa');
|
|
||||||
// return (loginStatus.fortyTwo && loginStatus.tfa);
|
|
||||||
// console.log($loginStatus.fortyTwo)
|
|
||||||
console.log(fortyTwo);
|
|
||||||
console.log(tfa);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}),
|
|
||||||
'/profile': wrap({
|
|
||||||
component: ProfilePage,
|
|
||||||
conditions: [
|
|
||||||
(detail) => {
|
|
||||||
const { fortyTwo, tfa } = get(loginStatus);
|
|
||||||
// console.log(fortyTwo);
|
|
||||||
// console.log(tfa);
|
|
||||||
// return true;
|
|
||||||
return (fortyTwo && tfa);
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}),
|
|
||||||
'/profile/*': wrap({
|
|
||||||
component: ProfilePage,
|
|
||||||
conditions: [
|
|
||||||
(detail) => {
|
|
||||||
const { fortyTwo, tfa } = get(loginStatus);
|
|
||||||
// console.log(fortyTwo);
|
|
||||||
// console.log(tfa);
|
|
||||||
// return true;
|
|
||||||
return (fortyTwo && tfa);
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}),
|
|
||||||
'/unauthorized-access': UnauthorizedAccessPage,
|
'/unauthorized-access': UnauthorizedAccessPage,
|
||||||
'*': NotFound
|
"*": NotFound
|
||||||
};
|
};
|
||||||
|
|
||||||
// export const primaryRoutes = {
|
// export const primaryRoutes = {
|
||||||
@@ -70,6 +100,7 @@ export const primaryRoutes = {
|
|||||||
// "*": NotFound
|
// "*": NotFound
|
||||||
// };
|
// };
|
||||||
|
|
||||||
|
|
||||||
// i might need to add /profile/* and such to make the nested routers work
|
// i might need to add /profile/* and such to make the nested routers work
|
||||||
|
|
||||||
// ok maybe these need to be in their own files?
|
// ok maybe these need to be in their own files?
|
||||||
|
|||||||
Reference in New Issue
Block a user