Skip to content

Commit 0200a71

Browse files
ログイン判定を行い、ログインページにリダイレクトする #15
1 parent ef3a28e commit 0200a71

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/routes/main/+page.server.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { redirect } from "@sveltejs/kit";
2+
import type { PageServerLoad } from "./$types";
3+
4+
export const load: PageServerLoad = async ({ locals }) => {
5+
if (!locals.user) throw redirect(302, '/login')
6+
}

src/routes/main/+page.svelte

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script lang="ts">
2+
import { page } from '$app/stores'
3+
</script>
4+
5+
<svelte:head>
6+
<title>Main page</title>
7+
</svelte:head>
8+
9+
{#if $page.data.user}
10+
<h1>Welcome {$page.data.user.username}</h1>
11+
Role: {$page.data.user.role}
12+
{:else}
13+
<h1>Welcome</h1>
14+
{/if}

0 commit comments

Comments
 (0)