🐛 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';
export async function load({ session }) {
if (session.authenticated) {
export async function load({ parent }) {
const { email } = await parent();
if (email) {
throw redirect(302, '/dashboard');
}
return {};
@@ -1,7 +1,8 @@
import { redirect } from '@sveltejs/kit';
export async function load({ session }) {
if (session.authenticated) {
export async function load({ parent }) {
const { email } = await parent();
if (email) {
throw redirect(302, '/dashboard');
}
return {};
@@ -1,10 +1,11 @@
import { redirect } from '@sveltejs/kit';
export async function load({ session }) {
if (!session.authenticated) {
export async function load({ parent }) {
const { email } = await parent();
if (!email) {
throw redirect(302, '/account/login?returnTo=/account/settings');
}
return {
email: session.email
email
};
}
@@ -1,7 +1,8 @@
import { redirect } from '@sveltejs/kit';
export async function load({ session, url }) {
if (!session.authenticated) {
export async function load({ parent, url }) {
const { email } = await parent();
if (!email) {
throw redirect(302, '/account/login');
}
const token = url.searchParams.get('token');
+4
View File
@@ -52,6 +52,8 @@
players = [...players, int_data];
});
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');
});
@@ -74,6 +76,8 @@
const confirmUnload = () => {
if (warnToLeave) {
event.preventDefault();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
event.returnValue = '';
}
};
@@ -1,12 +1,10 @@
import { redirect } from '@sveltejs/kit';
import { signedIn } from '$lib/stores';
export async function load({ session }) {
if (!session.authenticated) {
export async function load({ parent }) {
const { email } = await parent();
if (!email) {
throw redirect(302, '/account/login?returnTo=/create');
}
if (session.authenticated) {
signedIn.set(true);
}
return {};
}
@@ -1,10 +1,12 @@
import { redirect } from '@sveltejs/kit';
export async function load({ session }) {
if (!session.authenticated) {
export const load = async ({ parent }) => {
const { email } = await parent();
if (!email) {
throw redirect(302, '/account/login?returnTo=/dashboard');
}
return {
email: session.email
email
};
}
};
@@ -1,13 +1,14 @@
import { redirect, error } from '@sveltejs/kit';
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');
if (!session.authenticated) {
const { email } = await parent();
if (!email) {
throw redirect(302, `/account/login?returnTo=/edit?quiz_id=${quiz_id}`);
}
if (session.authenticated) {
if (email) {
signedIn.set(true);
}
@@ -1,14 +1,15 @@
import { redirect } from '@sveltejs/kit';
import { signedIn } from '$lib/stores';
export async function load({ session }) {
if (!session.authenticated) {
export async function load({ parent }) {
const { email } = await parent();
if (!email) {
throw redirect(302, '/account/login?returnTo=/import');
} else {
if (session.authenticated) {
if (email) {
signedIn.set(true);
}
}
return {
email: session.email
email
};
}
@@ -1,7 +1,8 @@
import { signedIn } from '$lib/stores';
export async function load({ url, session }) {
if (session.authenticated) {
export async function load({ url, parent }) {
const { email } = await parent();
if (email) {
signedIn.set(true);
}
const token = url.searchParams.get('pin');
+9 -5
View File
@@ -1,8 +1,4 @@
<!--
- 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/.
-->
<!--suppress ALL -->
<script lang="ts">
import { socket } from '$lib/socket';
import JoinGame from '$lib/play/join.svelte';
@@ -49,6 +45,8 @@
const confirmUnload = () => {
event.preventDefault();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
event.returnValue = '';
};
@@ -94,6 +92,12 @@
// The rest
</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:head>
<title>ClassQuiz - Play</title>
@@ -1,16 +1,16 @@
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 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) {
throw error(404);
} else if (res.status === 200) {
const quiz = await res.json();
return {
quiz: quiz,
logged_in: session.authenticated
logged_in: Boolean(email)
};
} else {
throw error(500);