Skip to content

Commit 8b73e52

Browse files
committed
adjust login components
1 parent 2d3680a commit 8b73e52

3 files changed

Lines changed: 68 additions & 63 deletions

File tree

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
<script lang="ts">
22
import LayoutWrapper from '../(layout-partials)/LayoutWrapper.svelte';
3-
4-
import { enhance } from '$app/forms';
5-
import type { ActionData } from './$types';
6-
7-
import { ccdSignInWithEmailAndPassword } from '$lib/client/firebase';
8-
9-
import { toastStore } from '@codingcatdev/blackcatui';
10-
113
import GoogleAuth from './GoogleAuth.svelte';
124
import TwitterAuth from './TwitterAuth.svelte';
135
import GitHubAuth from './GitHubAuth.svelte';
@@ -16,68 +8,18 @@
168
// export let form: ActionData;
179
1810
import type { PageData } from './$types';
11+
import EmailAuth from './EmailAuth.svelte';
1912
export let data: PageData;
2013
$: action = `?/login&redirectTo=${data.redirectTo ? data.redirectTo : '/dashboard'}`;
2114
</script>
2215

2316
<LayoutWrapper>
2417
<section class="bcu-card flex flex-col gap-4 p-4">
25-
<form
26-
class="flex justify-center w-full"
27-
method="POST"
28-
{action}
29-
use:enhance={async ({ action, cancel, controller, data, form }) => {
30-
// `form` is the `<form>` element
31-
// `data` is its `FormData` object
32-
// `action` is the URL to which the form is posted
33-
// `cancel()` will prevent the submission
34-
35-
const email = `${data.get('email')}`;
36-
const password = `${data.get('password')}`;
37-
38-
if (!email || !password) {
39-
toastStore.trigger({
40-
message: 'Please Provide Username and Password.'
41-
});
42-
cancel();
43-
} else {
44-
try {
45-
await ccdSignInWithEmailAndPassword({ email, password });
46-
} catch (err) {
47-
if (err instanceof Error) {
48-
toastStore.trigger({
49-
message: err.message,
50-
background: 'variant-filled-error'
51-
});
52-
}
53-
}
54-
}
55-
56-
return async ({ result, update }) => {
57-
// `result` is an `ActionResult` object
58-
// `update` is a function which triggers the logic that would be triggered if this callback wasn't set
59-
60-
update();
61-
};
62-
}}
63-
>
64-
<div class="flex flex-col gap-4 text-token">
65-
<label class="label">
66-
<span>Email</span>
67-
<input class="input" name="email" type="email" placeholder="codercatdev" />
68-
</label>
69-
<label class="label">
70-
<span>Password</span>
71-
<input class="input" name="password" type="password" placeholder="****" />
72-
</label>
73-
<button class="bcu-button variant-filled-primary" type="submit">Login</button>
74-
</div>
75-
</form>
76-
18+
<EmailAuth {action} />
7719
<hr />
7820

7921
<GoogleAuth {action} />
80-
<TwitterAuth />
81-
<GitHubAuth />
22+
<!-- <TwitterAuth /> -->
23+
<GitHubAuth {action} />
8224
</section>
8325
</LayoutWrapper>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<script lang="ts">
2+
import { enhance } from '$app/forms';
3+
import type { ActionData } from './$types';
4+
5+
import { ccdSignInWithEmailAndPassword } from '$lib/client/firebase';
6+
7+
import { toastStore } from '@codingcatdev/blackcatui';
8+
9+
export let action: string;
10+
</script>
11+
12+
<form
13+
class="flex justify-center w-full"
14+
method="POST"
15+
{action}
16+
use:enhance={async ({ action, cancel, controller, data, form }) => {
17+
// `form` is the `<form>` element
18+
// `data` is its `FormData` object
19+
// `action` is the URL to which the form is posted
20+
// `cancel()` will prevent the submission
21+
22+
const email = `${data.get('email')}`;
23+
const password = `${data.get('password')}`;
24+
25+
if (!email || !password) {
26+
toastStore.trigger({
27+
message: 'Please Provide Username and Password.'
28+
});
29+
cancel();
30+
} else {
31+
try {
32+
await ccdSignInWithEmailAndPassword({ email, password });
33+
} catch (err) {
34+
if (err instanceof Error) {
35+
toastStore.trigger({
36+
message: err.message,
37+
background: 'variant-filled-error'
38+
});
39+
}
40+
}
41+
}
42+
43+
return async ({ result, update }) => {
44+
// `result` is an `ActionResult` object
45+
// `update` is a function which triggers the logic that would be triggered if this callback wasn't set
46+
47+
update();
48+
};
49+
}}
50+
>
51+
<div class="flex flex-col gap-4 text-token">
52+
<label class="label">
53+
<span>Email</span>
54+
<input class="input" name="email" type="email" placeholder="codercatdev" />
55+
</label>
56+
<label class="label">
57+
<span>Password</span>
58+
<input class="input" name="password" type="password" placeholder="****" />
59+
</label>
60+
<button class="bcu-button variant-filled-primary" type="submit">Login</button>
61+
</div>
62+
</form>

‎apps/codingcatdev/src/routes/login/GitHubAuth.svelte‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
1010
// Display
1111
import { enhance } from '$app/forms';
12+
export let action: string;
1213
</script>
1314

1415
<form
1516
class="flex justify-center w-full"
1617
method="POST"
17-
action="?/login"
18+
{action}
1819
use:enhance={async ({ action, cancel, controller, data, form }) => {
1920
await ccdSignInWithPopUp(provider);
2021

0 commit comments

Comments
 (0)