diff --git a/srcs/requirements/svelte/api_front/src/SplashPage.svelte b/srcs/requirements/svelte/api_front/src/SplashPage.svelte index d9c5f6ad..b943b6aa 100644 --- a/srcs/requirements/svelte/api_front/src/SplashPage.svelte +++ b/srcs/requirements/svelte/api_front/src/SplashPage.svelte @@ -5,6 +5,7 @@ import { loginStatus } 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') diff --git a/srcs/requirements/svelte/api_front/src/components/Header.svelte b/srcs/requirements/svelte/api_front/src/components/Header.svelte index 08079ff0..dee36e33 100644 --- a/srcs/requirements/svelte/api_front/src/components/Header.svelte +++ b/srcs/requirements/svelte/api_front/src/components/Header.svelte @@ -1,23 +1,12 @@ -
- Potato Pong Logo - -

Potato Pong

- + Potato Pong Logo (push('/'))}> + +

Potato Pong

+
- - -{#if $location === '/profile/fetch'} -

Made it to /fetch

- - - - - - {#if promise !== undefined} - - -

{promise.username}

- {/if} -{/if} - - - - - diff --git a/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js b/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js index cdde6640..c662b26d 100644 --- a/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js +++ b/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js @@ -11,55 +11,85 @@ import { get } from 'svelte/store'; // "/article/:title": Article, // this is how you would do parameters! // "/": 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 = { - '/': 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); - } - ] - }), + "/": SplashPage, + "/profile": ProfilePage, + "/profile/*": ProfilePage, '/unauthorized-access': UnauthorizedAccessPage, - '*': NotFound + "*": NotFound }; // export const primaryRoutes = { @@ -70,6 +100,7 @@ export const primaryRoutes = { // "*": NotFound // }; + // i might need to add /profile/* and such to make the nested routers work // ok maybe these need to be in their own files?