Skip to content

Commit d4442ec

Browse files
ログイン後、ログアウト後にルートページを表示する #17
1 parent 0200a71 commit d4442ec

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

src/routes/+layout.svelte

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
<!--
12
<script lang="ts">
23
import { page } from '$app/stores'
34
</script>
5+
-->
46

57
<svelte:head>
68
<title> SvelteKit Authentication</title>
79
</svelte:head>
810

9-
<nav>
11+
<!-- <nav>
1012
{#if $page.data.user}
11-
<!-- <a href="/admin">Admin</a> -->
13+
<a href="/main">Main</a>
1214
1315
<form action="/logout" method="POST">
1416
<button type="submit">Log out</button>
@@ -17,7 +19,7 @@
1719
<a href="/login">Log in</a>
1820
<a href="/register">Register</a>
1921
{/if}
20-
</nav>
22+
</nav> -->
2123

2224
<main>
2325
<slot />

src/routes/+page.svelte

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
<script lang="ts">
2+
import { page } from '$app/stores'
3+
</script>
4+
5+
<svelte:head>
6+
<title>SvelteKit Authentication</title>
7+
</svelte:head>
8+
19
<h1>Welcome to SvelteKit Authentication</h1>
2-
<p>Visit <a href="https://github.com/sinProject-Inc/sveltekit_authentication">GitHub Repository</a> to read the documentation</p>
10+
<p>
11+
Visit <a href="https://github.com/sinProject-Inc/sveltekit_authentication">GitHub Repository</a> to
12+
read the documentation
13+
</p>
14+
15+
{#if $page.data.user}
16+
<a href="/main">Main</a>
317

18+
<form action="/logout" method="POST">
19+
<button type="submit">Log out</button>
20+
</form>
21+
{:else}
22+
<a href="/login">Log in</a>
23+
<a href="/register">Register</a>
24+
{/if}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export const actions: Actions = {
1212
expires: new Date(0),
1313
})
1414

15-
throw redirect(302, '/login')
15+
throw redirect(302, '/')
1616
}
1717
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { redirect } from "@sveltejs/kit";
22
import type { PageServerLoad } from "./$types";
33

44
export const load: PageServerLoad = async ({ locals }) => {
5-
if (!locals.user) throw redirect(302, '/login')
5+
if (!locals.user) throw redirect(302, '/')
66
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ export const actions: Actions = {
3535
return invalid(400, { user_exists: true })
3636
}
3737

38-
console.log('aaa')
39-
4038
throw redirect(303, '/login')
4139
},
4240
}

0 commit comments

Comments
 (0)