Skip to content

Commit 6a15279

Browse files
Sign in, Sign out に書き換える #33
データベースに必要なデータを準備する処理を作成する #37
1 parent 8e513c5 commit 6a15279

File tree

13 files changed

+41
-24
lines changed

13 files changed

+41
-24
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = {
4444
},
4545
{
4646
selector: ['method', 'function'],
47-
format: ['camelCase', 'UPPER_CASE'],
47+
format: ['camelCase', 'UPPER_CASE', 'snake_case'],
4848
},
4949
{
5050
selector: [

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "sveltekit-login",
2+
"name": "sveltekit_authentication",
33
"version": "0.0.1",
44
"private": true,
55
"scripts": {

src/routes/+layout.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
{#if $page.data.user}
1111
<a href="/main">Main</a>
1212
13-
<form action="/logout" method="POST">
14-
<button type="submit">Log out</button>
13+
<form action="/sign_out" method="POST">
14+
<button type="submit">Sign out</button>
1515
</form>
1616
{:else}
17-
<a href="/login">Log in</a>
17+
<a href="/sign_in">Sign in</a>
1818
<a href="/register">Register</a>
1919
{/if}
2020
</nav> -->
2121

2222

2323

24-
{#if $page.url.pathname != '/login' && !$page.data.user}
24+
{#if $page.url.pathname != '/sign_in' && !$page.data.user}
2525
<script src="https://accounts.google.com/gsi/client" async defer></script>
2626
<div
2727
id="g_id_onload"

src/routes/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
{#if $page.data.user}
1616
<a href="/main">Main</a>
1717

18-
<form action="/logout" method="POST">
18+
<form action="/sign_out" method="POST">
1919
<button type="submit">Log out</button>
2020
</form>
2121
{:else}
22-
<a href="/login">Log in / Register</a>
22+
<a href="/sign_in">Sign in / Sign up</a>
2323
{/if}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { db } from '$lib/database'
2+
import type { RequestHandler } from '@sveltejs/kit'
3+
4+
export const GET: RequestHandler = async () => {
5+
try {
6+
await db.role.create({ data: { name: 'admin' } })
7+
await db.role.create({ data: { name: 'user' } })
8+
9+
await db.appSetting.create({ data: { key: 'session_lifetime_sec', value: '600' } })
10+
await db.appSetting.create({ data: { key: 'pin_code_lifetime_sec', value: '300' } })
11+
12+
return new Response('Success')
13+
} catch (error) {
14+
console.error(error)
15+
return new Response('Error')
16+
}
17+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { PageServerLoad } from "./$types";
66
export const load: PageServerLoad = async ({ locals, url }) => {
77
const redirect_url = new URL(url.origin)
88

9-
redirect_url.pathname = '/login'
9+
redirect_url.pathname = '/sign_in'
1010
redirect_url.searchParams.set('redirect_url', url.pathname)
1111

1212
if (!locals.user) throw redirect(302, redirect_url.toString())

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function decodeJwtResponse(credential: string): GoogleCredential {
6464
}
6565

6666
export const actions: Actions = {
67-
login: async ({ request }) => {
67+
sign_in: async ({ request }) => {
6868
const data = await request.formData()
6969
const email = data.get('email')?.toString() ?? ''
7070

@@ -126,6 +126,6 @@ export const actions: Actions = {
126126

127127
await Auth.signIn(user.id, cookies)
128128

129-
throw redirect(302, '/login')
129+
throw redirect(302, '/sign_in')
130130
},
131131
}

src/routes/pin_code/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
1111
onMount(() => {
12-
if (!form) location.href = '/login'
12+
if (!form) location.href = '/sign_in'
1313
1414
document.onfocus = (event) => {
1515
if (event.target instanceof HTMLInputElement) event.target.select()
File renamed without changes.

0 commit comments

Comments
 (0)