From 657460b8ae9fa37b04699d37b5f6eba6d55dd286 Mon Sep 17 00:00:00 2001 From: Me Date: Tue, 6 Dec 2022 16:56:35 +0100 Subject: [PATCH] ok so i added the fetch(user) in the conditions of the routing, works just fine, but still need to add some stuff, like passing on params and special conditions for special pages --- .../src/pages/profile/ProfileDisplay.svelte | 1 + .../api_front/src/routes/primaryRoutes.js | 169 +++++++++++++----- 2 files changed, 127 insertions(+), 43 deletions(-) diff --git a/srcs/requirements/svelte/api_front/src/pages/profile/ProfileDisplay.svelte b/srcs/requirements/svelte/api_front/src/pages/profile/ProfileDisplay.svelte index b80a8572..9bbb5c3f 100644 --- a/srcs/requirements/svelte/api_front/src/pages/profile/ProfileDisplay.svelte +++ b/srcs/requirements/svelte/api_front/src/pages/profile/ProfileDisplay.svelte @@ -26,6 +26,7 @@ // i think i don't need to do this once i sort out the {wrap} conditions: in theory i could pass values to the Route // once the async authentication check is done onMount( async() => { + // so ideally i wouldn't do this user = await fetch('http://transcendance:8080/api/v2/user') .then( (x) => x.json() ); diff --git a/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js b/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js index 77651f68..ce37239a 100644 --- a/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js +++ b/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js @@ -86,49 +86,135 @@ import { userStore, userLogout } from "../stores/loginStatusStore"; // }; export const primaryRoutes = { - "/": SplashPage, - '/test': wrap({ - component: TestPage, - conditions: [ - (detail) => { - const user = get(userStore); // seems like get(store) is not an option - // // const user = userStore; - // // console.log(fortyTwo); - // // console.log(tfa); - // console.log('in /test what is in user') - // console.log(user) - - // you moron $userStore is a Svelte Abreviation, this is .JS, duh - // let user = $userStore; - // let user; - // const unsub = userStore.subscribe(value => { - // console.log(value); - // user = value; - // }); - console.log('in /test what is in userStore directly') - console.log(user) - - // return true; - // obvi this doesn't work cuz skips to true after no user... - // you gotta make the condition the true and the everything else false - // if (user && user.statusCode && user.statusCode === 403) - // if (user && user.username) { - if (user !== null) { - unsub(); - return true; - } else { - unsub(); - return false; - } - } - ] - }), + '/': SplashPage, + '/2fa': TwoFactorAuthentication, // '/test': wrap({ // component: TestPage, // conditions: [ + // (detail) => { + // const user = get(userStore); // seems like get(store) is not an option + // // // const user = userStore; + // // // console.log(fortyTwo); + // // // console.log(tfa); + // // console.log('in /test what is in user') + // // console.log(user) + + // // you moron $userStore is a Svelte Abreviation, this is .JS, duh + // // let user = $userStore; + // // let user; + // // const unsub = userStore.subscribe(value => { + // // console.log(value); + // // user = value; + // // }); + // console.log('in /test what is in userStore directly') + // console.log(user) + + // // return true; + // // obvi this doesn't work cuz skips to true after no user... + // // you gotta make the condition the true and the everything else false + // // if (user && user.statusCode && user.statusCode === 403) + // // if (user && user.username) { + // if (user !== null) { + // unsub(); + // return true; + // } else { + // unsub(); + // return false; + // } + // } + // ] + // }), + '/test': wrap({ + component: TestPage, + conditions: [ + async(detail) => { + // THIS SHIT TOTALLY WORKS + // Yea in the end this might be the best thing, like also from a Security point of view + const user = await fetch('http://transcendance:8080/api/v2/user') + .then((resp) => resp.json()) + + console.log('in /test what is in user') + console.log(user) + + if (user && user.username) + return true; + else + return false; + } + ] + }), + '/profile': wrap({ + component: ProfilePage, + conditions: [ + async(detail) => { + const user = await fetch('http://transcendance:8080/api/v2/user') + .then((resp) => resp.json()) + + console.log('in /test what is in user') + console.log(user) + + if (user && user.username) + return true; + else + return false; + } + ] + }), + '/profile/*': wrap({ + component: ProfilePage, + conditions: [ + async(detail) => { + const user = await fetch('http://transcendance:8080/api/v2/user') + .then((resp) => resp.json()) + + console.log('in /test what is in user') + console.log(user) + + if (user && user.username) + return true; + else + return false; + } + ] + }), + // '/game': wrap({ + // component: ProfilePage, + // conditions: [ + // async(detail) => { + // const user = await fetch('http://transcendance:8080/api/v2/user') + // .then((resp) => resp.json()) + + // console.log('in /test what is in user') + // console.log(user) + + // if (user && user.username) + // return true; + // else + // return false; + // } + // ] + // }), + // '/spectate': wrap({ + // component: ProfilePage, + // conditions: [ + // async(detail) => { + // const user = await fetch('http://transcendance:8080/api/v2/user') + // .then((resp) => resp.json()) + + // console.log('in /test what is in user') + // console.log(user) + + // if (user && user.username) + // return true; + // else + // return false; + // } + // ] + // }), + // '/chat': wrap({ + // component: ProfilePage, + // conditions: [ // async(detail) => { - // // THIS SHIT TOTALLY WORKS - // // Yea in the end this might be the best thing, like also from a Security point of view // const user = await fetch('http://transcendance:8080/api/v2/user') // .then((resp) => resp.json()) @@ -142,11 +228,8 @@ export const primaryRoutes = { // } // ] // }), - '/2fa': TwoFactorAuthentication, - "/profile": ProfilePage, - "/profile/*": ProfilePage, '/unauthorized-access': UnauthorizedAccessPage, - "*": NotFound + '*': NotFound }; // export const primaryRoutes = {