Fix error in logout procedure and guard for each route (#439)

This commit is contained in:
Alex
2022-08-07 18:36:34 -05:00
committed by GitHub
parent f881981c44
commit 28c7736ecd
9 changed files with 58 additions and 20 deletions

View File

@@ -1,21 +1,20 @@
<script context="module" lang="ts">
export const prerender = false;
import { browser } from '$app/env';
import type { Load } from '@sveltejs/kit';
export const load: Load = async ({ fetch }) => {
try {
await fetch('/data/user/get-my-user-info');
return {
status: 302,
redirect: '/photos'
};
} catch (e) {
export const load: Load = async ({ session }) => {
if (!browser && !session.user) {
return {
status: 302,
redirect: '/auth/login'
};
} else {
return {
status: 302,
redirect: '/photos'
};
}
};
</script>

View File

@@ -3,8 +3,14 @@
import type { Load } from '@sveltejs/kit';
import { setAssetInfo } from '$lib/stores/assets';
export const load: Load = async ({ fetch, session }) => {
if (!browser && !session.user) {
return {
status: 302,
redirect: '/auth/login'
};
}
export const load: Load = async ({ fetch }) => {
try {
const [userInfo, assets] = await Promise.all([
fetch('/data/user/get-my-user-info').then((r) => r.json()),
@@ -40,6 +46,7 @@
import { openFileUploadDialog, UploadType } from '$lib/utils/file-uploader';
import { AssetResponseDto, UserResponseDto } from '@api';
import SideBar from '$lib/components/shared-components/side-bar/side-bar.svelte';
import { browser } from '$app/env';
export let user: UserResponseDto;