Skip to content

Commit e95fde2

Browse files
committed
✨ Ensure easy access to guest account (#1232)
1 parent d795626 commit e95fde2

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/lib/components/AuthForm.svelte

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
import { Card, Button, Label, Input } from 'flowbite-svelte';
33
44
// 必要なコンポーネントだけを読み込んで、コンパイルを時間を短縮
5-
// モジュールは読み込めているのに以下のエラーが発生するため、やむなく@ts-ignoreを使用
6-
// Cannot find module 'flowbite-svelte-icons/xxx.svelte' or its corresponding type declarations.ts(2307)
7-
// @ts-ignore
5+
import Checkbox from 'flowbite-svelte/Checkbox.svelte';
86
import UserOutlineSolid from 'flowbite-svelte-icons/UserCircleSolid.svelte';
9-
// @ts-ignore
107
import EyeOutline from 'flowbite-svelte-icons/EyeOutline.svelte';
11-
// @ts-ignore
128
import EyeSlashOutline from 'flowbite-svelte-icons/EyeSlashOutline.svelte';
139
1410
import MessageHelperWrapper from '$lib/components/MessageHelperWrapper.svelte';
1511
12+
import {
13+
GUEST_USER_NAME,
14+
GUEST_USER_PASSWORD,
15+
// GUEST_USER_PASSWORD_FOR_LOCAL,
16+
LOGIN_LABEL,
17+
} from '$lib/constants/forms';
18+
1619
// FIXME: 構造体に相当するものを利用した方が拡張・修正がしやすくなるかもしれせまん
1720
export let formProperties;
1821
export let title: string;
@@ -23,11 +26,26 @@
2326
2427
const { form, message, errors, submitting, enhance } = formProperties;
2528
29+
let isGuest: boolean = false;
30+
31+
$: if (isGuest) {
32+
$form.username = GUEST_USER_NAME;
33+
34+
// HACK: ローカル環境のパスワードは一時的に書き換えて対応している
35+
//
36+
// See:
37+
// src/lib/constants/forms.ts
38+
// $form.password = GUEST_USER_PASSWORD_FOR_LOCAL;
39+
$form.password = GUEST_USER_PASSWORD;
40+
} else {
41+
$form.username = '';
42+
$form.password = '';
43+
}
44+
2645
const UNFOCUSABLE = -1;
2746
let showPassword = false;
2847
</script>
2948

30-
<!-- TODO: ゲストユーザ(お試し用)としてログインできるようにする -->
3149
<!-- FIXME: コンポーネントが巨大になってきたと思われるので、分割しましょう -->
3250
<!-- TODO: containerのデフォルト値を設定できないか? -->
3351
<!-- See: -->
@@ -40,6 +58,10 @@
4058

4159
<MessageHelperWrapper message={$message} />
4260

61+
{#if title === LOGIN_LABEL}
62+
<Checkbox bind:checked={isGuest}>お試し用のアカウントを使う</Checkbox>
63+
{/if}
64+
4365
<!-- User name -->
4466
<div class="space-y-2">
4567
<Label for="username-in-auth-form">

src/lib/constants/forms.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
export const CREATE_ACCOUNT_LABEL: string = 'アカウントを作成';
22
export const LOGIN_LABEL: string = 'ログイン';
3+
4+
export const GUEST_USER_NAME: string = 'guest';
5+
6+
// Note: 2024年9月時点では、staging環境、production環境を優先
7+
// ローカル環境では書き換えて対応
8+
// TODO: ローカル環境とstaging環境、production環境では値が異なるため、切り替えられるようにする
9+
export const GUEST_USER_PASSWORD_FOR_LOCAL: string = 'Ch0kuda1';
10+
export const GUEST_USER_PASSWORD: string = 'Hell0Guest';

0 commit comments

Comments
 (0)