primaryRoutes.js fetch() fix and refactoring
This commit is contained in:
@@ -7,96 +7,41 @@ import { wrap } from 'svelte-spa-router/wrap'
|
||||
import Game from '../pages/game/Game.svelte';
|
||||
import Ranking from '../pages/game/Ranking.svelte';
|
||||
import GameSpectator from '../pages/game/GameSpectator.svelte';
|
||||
import { fetchUser } from "../pieces/utils";
|
||||
|
||||
async function checkLogin(detail) {
|
||||
const user = await fetchUser();
|
||||
if (!user || !user.username) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export const primaryRoutes = {
|
||||
'/': SplashPage,
|
||||
'/2fa': TwoFactorAuthentication,
|
||||
'/game': wrap({
|
||||
component: Game,
|
||||
conditions: [
|
||||
async(detail) => {
|
||||
const user = await fetch('http://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
|
||||
.then((resp) => resp.json())
|
||||
|
||||
console.log('in /profile what is in user')
|
||||
console.log(user)
|
||||
|
||||
if (user && user.username)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
]
|
||||
}),
|
||||
'/spectator': wrap({
|
||||
component: GameSpectator,
|
||||
conditions: [
|
||||
async(detail) => {
|
||||
const user = await fetch('http://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
|
||||
.then((resp) => resp.json())
|
||||
|
||||
console.log('in /profile what is in user')
|
||||
console.log(user)
|
||||
|
||||
if (user && user.username)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
]
|
||||
}),
|
||||
'/ranking': wrap({
|
||||
component: Ranking,
|
||||
conditions: [
|
||||
async(detail) => {
|
||||
const user = await fetch('http://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
|
||||
.then((resp) => resp.json())
|
||||
|
||||
console.log('in /profile 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://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
|
||||
.then((resp) => resp.json())
|
||||
|
||||
console.log('in /profile 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://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
|
||||
.then((resp) => resp.json())
|
||||
|
||||
console.log('in /profile/* what is in user')
|
||||
console.log(user)
|
||||
|
||||
if (user && user.username)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
]
|
||||
}),
|
||||
'/unauthorized-access': UnauthorizedAccessPage,
|
||||
'*': NotFound
|
||||
'/': SplashPage,
|
||||
'/2fa': TwoFactorAuthentication,
|
||||
'/game': wrap({
|
||||
component: Game,
|
||||
conditions: [checkLogin]
|
||||
}),
|
||||
'/spectator': wrap({
|
||||
component: GameSpectator,
|
||||
conditions: [checkLogin]
|
||||
}),
|
||||
'/ranking': wrap({
|
||||
component: Ranking,
|
||||
conditions: [checkLogin]
|
||||
}),
|
||||
'/profile': wrap({
|
||||
component: ProfilePage,
|
||||
conditions: [checkLogin]
|
||||
}),
|
||||
'/profile/*': wrap({
|
||||
component: ProfilePage,
|
||||
conditions: [checkLogin]
|
||||
}),
|
||||
'/unauthorized-access': UnauthorizedAccessPage,
|
||||
'*': NotFound
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user