🐛 Fixed more errors coming from upgrading SvelteKit

This commit is contained in:
Mawoka
2022-08-18 17:07:02 +02:00
parent cacd727c0e
commit dcddb3b764
14 changed files with 51 additions and 36 deletions
@@ -1,7 +1,8 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
export async function load({ session }) { export async function load({ parent }) {
if (session.authenticated) { const { email } = await parent();
if (email) {
throw redirect(302, '/dashboard'); throw redirect(302, '/dashboard');
} }
return {}; return {};
@@ -1,7 +1,8 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
export async function load({ session }) { export async function load({ parent }) {
if (session.authenticated) { const { email } = await parent();
if (email) {
throw redirect(302, '/dashboard'); throw redirect(302, '/dashboard');
} }
return {}; return {};
@@ -1,10 +1,11 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
export async function load({ session }) { export async function load({ parent }) {
if (!session.authenticated) { const { email } = await parent();
if (!email) {
throw redirect(302, '/account/login?returnTo=/account/settings'); throw redirect(302, '/account/login?returnTo=/account/settings');
} }
return { return {
email: session.email email
}; };
} }
@@ -1,7 +1,8 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
export async function load({ session, url }) { export async function load({ parent, url }) {
if (!session.authenticated) { const { email } = await parent();
if (!email) {
throw redirect(302, '/account/login'); throw redirect(302, '/account/login');
} }
const token = url.searchParams.get('token'); const token = url.searchParams.get('token');
+4
View File
@@ -52,6 +52,8 @@
players = [...players, int_data]; players = [...players, int_data];
}); });
socket.on('already_registered_as_admin', () => { socket.on('already_registered_as_admin', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
errorMessage = $t('admin_page.already_registered_as_admin'); errorMessage = $t('admin_page.already_registered_as_admin');
}); });
@@ -74,6 +76,8 @@
const confirmUnload = () => { const confirmUnload = () => {
if (warnToLeave) { if (warnToLeave) {
event.preventDefault(); event.preventDefault();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
event.returnValue = ''; event.returnValue = '';
} }
}; };
@@ -1,12 +1,10 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
import { signedIn } from '$lib/stores'; import { signedIn } from '$lib/stores';
export async function load({ session }) { export async function load({ parent }) {
if (!session.authenticated) { const { email } = await parent();
if (!email) {
throw redirect(302, '/account/login?returnTo=/create'); throw redirect(302, '/account/login?returnTo=/create');
} }
if (session.authenticated) {
signedIn.set(true);
}
return {}; return {};
} }
@@ -1,10 +1,12 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
export async function load({ session }) { export const load = async ({ parent }) => {
if (!session.authenticated) { const { email } = await parent();
if (!email) {
throw redirect(302, '/account/login?returnTo=/dashboard'); throw redirect(302, '/account/login?returnTo=/dashboard');
} }
return { return {
email: session.email email
}; };
} };
@@ -1,13 +1,14 @@
import { redirect, error } from '@sveltejs/kit'; import { redirect, error } from '@sveltejs/kit';
import { signedIn } from '$lib/stores'; import { signedIn } from '$lib/stores';
export async function load({ url, session }) { export async function load({ url, parent }) {
const quiz_id = url.searchParams.get('quiz_id'); const quiz_id = url.searchParams.get('quiz_id');
if (!session.authenticated) { const { email } = await parent();
if (!email) {
throw redirect(302, `/account/login?returnTo=/edit?quiz_id=${quiz_id}`); throw redirect(302, `/account/login?returnTo=/edit?quiz_id=${quiz_id}`);
} }
if (session.authenticated) { if (email) {
signedIn.set(true); signedIn.set(true);
} }
@@ -1,14 +1,15 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
import { signedIn } from '$lib/stores'; import { signedIn } from '$lib/stores';
export async function load({ session }) { export async function load({ parent }) {
if (!session.authenticated) { const { email } = await parent();
if (!email) {
throw redirect(302, '/account/login?returnTo=/import'); throw redirect(302, '/account/login?returnTo=/import');
} else { } else {
if (session.authenticated) { if (email) {
signedIn.set(true); signedIn.set(true);
} }
} }
return { return {
email: session.email email
}; };
} }
@@ -1,7 +1,8 @@
import { signedIn } from '$lib/stores'; import { signedIn } from '$lib/stores';
export async function load({ url, session }) { export async function load({ url, parent }) {
if (session.authenticated) { const { email } = await parent();
if (email) {
signedIn.set(true); signedIn.set(true);
} }
const token = url.searchParams.get('pin'); const token = url.searchParams.get('pin');
+9 -5
View File
@@ -1,8 +1,4 @@
<!-- <!--suppress ALL -->
- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/.
-->
<script lang="ts"> <script lang="ts">
import { socket } from '$lib/socket'; import { socket } from '$lib/socket';
import JoinGame from '$lib/play/join.svelte'; import JoinGame from '$lib/play/join.svelte';
@@ -49,6 +45,8 @@
const confirmUnload = () => { const confirmUnload = () => {
event.preventDefault(); event.preventDefault();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
event.returnValue = ''; event.returnValue = '';
}; };
@@ -94,6 +92,12 @@
// The rest // The rest
</script> </script>
<!--
- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/.
-->
<svelte:window on:beforeunload={confirmUnload} /> <svelte:window on:beforeunload={confirmUnload} />
<svelte:head> <svelte:head>
<title>ClassQuiz - Play</title> <title>ClassQuiz - Play</title>
@@ -1,16 +1,16 @@
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
import type { PageLoad } from '@sveltejs/kit';
export const load: PageLoad = async ({ params, fetch, session }) => { export const load = async ({ params, parent }) => {
const { quiz_id } = params; const { quiz_id } = params;
const res = await fetch(`/api/v1/quiz/get/public/${quiz_id}`); const res = await fetch(`${process.env.API_URL}/api/v1/quiz/get/public/${quiz_id}`);
const { email } = await parent();
if (res.status === 404 || res.status === 400) { if (res.status === 404 || res.status === 400) {
throw error(404); throw error(404);
} else if (res.status === 200) { } else if (res.status === 200) {
const quiz = await res.json(); const quiz = await res.json();
return { return {
quiz: quiz, quiz: quiz,
logged_in: session.authenticated logged_in: Boolean(email)
}; };
} else { } else {
throw error(500); throw error(500);