From 3480fe5326cfc18e51db34abcff8bf65911c6e08 Mon Sep 17 00:00:00 2001
From: Ben McCann <322311+benmccann@users.noreply.github.com>
Date: Sun, 18 Feb 2024 10:47:13 -0800
Subject: [PATCH] chore(web): remove createEventDispatcher from LoginForm
(#7177)
---
.../lib/components/forms/login-form.svelte | 20 +++++++++----------
web/src/routes/auth/login/+page.svelte | 6 +++---
2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/web/src/lib/components/forms/login-form.svelte b/web/src/lib/components/forms/login-form.svelte
index 81ea0c1a19..387c76be30 100644
--- a/web/src/lib/components/forms/login-form.svelte
+++ b/web/src/lib/components/forms/login-form.svelte
@@ -6,10 +6,14 @@
import { oauth } from '$lib/utils';
import { getServerErrorMessage, handleError } from '$lib/utils/handle-error';
import { getServerConfig, login } from '@immich/sdk';
- import { createEventDispatcher, onMount } from 'svelte';
+ import { onMount } from 'svelte';
import { fade } from 'svelte/transition';
import Button from '../elements/buttons/button.svelte';
+ export let onSuccess: () => unknown | Promise;
+ export let onFirstLogin: () => unknown | Promise;
+ export let onOnboarding: () => unknown | Promise;
+
let errorMessage: string;
let email = '';
let password = '';
@@ -17,12 +21,6 @@
let loading = false;
let oauthLoading = true;
- const dispatch = createEventDispatcher<{
- success: void;
- firstLogin: void;
- onboarding: void;
- }>();
-
onMount(async () => {
if (!$featureFlags.oauth) {
oauthLoading = false;
@@ -32,7 +30,7 @@
if (oauth.isCallback(window.location)) {
try {
await oauth.login(window.location);
- dispatch('success');
+ await onSuccess();
return;
} catch (error) {
console.error('Error [login-form] [oauth.callback]', error);
@@ -63,15 +61,15 @@
const serverConfig = await getServerConfig();
if (user.isAdmin && !serverConfig.isOnboarded) {
- dispatch('onboarding');
+ await onOnboarding();
return;
}
if (!user.isAdmin && user.shouldChangePassword) {
- dispatch('firstLogin');
+ await onFirstLogin();
return;
}
- dispatch('success');
+ await onSuccess();
return;
} catch (error) {
errorMessage = (await getServerErrorMessage(error)) || 'Incorrect email or password';
diff --git a/web/src/routes/auth/login/+page.svelte b/web/src/routes/auth/login/+page.svelte
index 2c19b5550a..199cd06e36 100644
--- a/web/src/routes/auth/login/+page.svelte
+++ b/web/src/routes/auth/login/+page.svelte
@@ -26,9 +26,9 @@
goto(AppRoute.PHOTOS, { invalidateAll: true })}
- on:firstLogin={() => goto(AppRoute.AUTH_CHANGE_PASSWORD)}
- on:onboarding={() => goto(AppRoute.AUTH_ONBOARDING)}
+ onSuccess={() => goto(AppRoute.PHOTOS, { invalidateAll: true })}
+ onFirstLogin={() => goto(AppRoute.AUTH_CHANGE_PASSWORD)}
+ onOnboarding={() => goto(AppRoute.AUTH_ONBOARDING)}
/>
{/if}