Skip to content

Commit 4711c5b

Browse files
Refactor login page to use derived profile
1 parent 3e58cc3 commit 4711c5b

2 files changed

Lines changed: 16 additions & 20 deletions

File tree

src/lib/profiles/index.svelte.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,4 @@ export const studio: Profile = {
233233
}
234234
};
235235

236-
const resolver = $derived(() => {
237-
switch (env.PUBLIC_CONSOLE_PROFILE) {
238-
case 'studio':
239-
return studio;
240-
default:
241-
return base;
242-
}
243-
});
244-
245-
export const resolvedProfile = resolver();
236+
export const resolvedProfile = env.PUBLIC_CONSOLE_PROFILE === 'studio' ? studio : base;

src/routes/(public)/(guest)/login/+page.svelte

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
import { Layout } from '@appwrite.io/pink-svelte';
1313
import { Logins, resolvedProfile } from '$lib/profiles/index.svelte';
1414
import type { OAuthProvider } from '@appwrite.io/console';
15+
import type { PageProps } from './$types.js';
1516
16-
let mail: string, pass: string, disabled: boolean;
17+
let mail: string = $state(''),
18+
pass: string = $state(''),
19+
disabled: boolean = $state(false);
1720
18-
export let data;
19-
const Unauthenticated = resolvedProfile.component.unauthenticated;
21+
let { data }: PageProps = $props();
22+
23+
const profile = $derived(resolvedProfile);
24+
const Unauthenticated = $derived(profile.component.unauthenticated);
2025
2126
async function login() {
2227
try {
@@ -92,15 +97,15 @@
9297
</script>
9398

9499
<svelte:head>
95-
<title>Sign in - {resolvedProfile.platform}</title>
100+
<title>Sign in - {profile.platform}</title>
96101
</svelte:head>
97102

98103
<Unauthenticated coupon={data?.couponData} campaign={data?.campaign}>
99104
<svelte:fragment slot="title">Sign in</svelte:fragment>
100105
<svelte:fragment>
101106
<Form onSubmit={login}>
102107
<Layout.Stack>
103-
{#if resolvedProfile.logins.includes(Logins.EMAIL)}
108+
{#if profile.logins.includes(Logins.EMAIL)}
104109
<InputEmail
105110
id="email"
106111
label="Email"
@@ -117,21 +122,21 @@
117122
<Button fullWidth submit {disabled}>Sign in</Button>
118123
<span class="with-separators eyebrow-heading-3">or</span>
119124
{/if}
120-
{#if resolvedProfile.logins.includes(Logins.GITHUB)}
125+
{#if profile.logins.includes(Logins.GITHUB)}
121126
<Button
122127
secondary
123128
fullWidth
124-
on:click={() => onOauthLogin(resolvedProfile.oauthProviders.github)}
129+
on:click={() => onOauthLogin(profile.oauthProviders.github)}
125130
{disabled}>
126131
<span class="icon-github" aria-hidden="true"></span>
127132
<span class="text">Sign in with GitHub</span>
128133
</Button>
129134
{/if}
130-
{#if resolvedProfile.logins.includes(Logins.GOOGLE)}
135+
{#if profile.logins.includes(Logins.GOOGLE)}
131136
<Button
132137
secondary
133138
fullWidth
134-
on:click={() => onOauthLogin(resolvedProfile.oauthProviders.google)}
139+
on:click={() => onOauthLogin(profile.oauthProviders.google)}
135140
{disabled}>
136141
<span class="icon-google" aria-hidden="true"></span>
137142
<span class="text">Sign in with Google</span>
@@ -141,7 +146,7 @@
141146
</Form>
142147
</svelte:fragment>
143148
<svelte:fragment slot="links">
144-
{#if resolvedProfile.logins.includes(Logins.EMAIL)}
149+
{#if profile.logins.includes(Logins.EMAIL)}
145150
<li class="inline-links-item">
146151
<a href={`${base}/recover`}><span class="text">Forgot password?</span></a>
147152
</li>

0 commit comments

Comments
 (0)