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

This commit is contained in:
Me
2022-12-06 16:56:35 +01:00
parent c79d6f9b7d
commit 657460b8ae
2 changed files with 127 additions and 43 deletions

View File

@@ -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 // 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 // once the async authentication check is done
onMount( async() => { onMount( async() => {
// so ideally i wouldn't do this
user = await fetch('http://transcendance:8080/api/v2/user') user = await fetch('http://transcendance:8080/api/v2/user')
.then( (x) => x.json() ); .then( (x) => x.json() );

View File

@@ -86,49 +86,135 @@ import { userStore, userLogout } from "../stores/loginStatusStore";
// }; // };
export const primaryRoutes = { export const primaryRoutes = {
"/": SplashPage, '/': SplashPage,
'/test': wrap({ '/2fa': TwoFactorAuthentication,
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({ // '/test': wrap({
// component: TestPage, // component: TestPage,
// conditions: [ // 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) => { // 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') // const user = await fetch('http://transcendance:8080/api/v2/user')
// .then((resp) => resp.json()) // .then((resp) => resp.json())
@@ -142,11 +228,8 @@ export const primaryRoutes = {
// } // }
// ] // ]
// }), // }),
'/2fa': TwoFactorAuthentication,
"/profile": ProfilePage,
"/profile/*": ProfilePage,
'/unauthorized-access': UnauthorizedAccessPage, '/unauthorized-access': UnauthorizedAccessPage,
"*": NotFound '*': NotFound
}; };
// export const primaryRoutes = { // export const primaryRoutes = {