2022-12-26 10:35:52 -05:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { goto } from '$app/navigation';
|
2023-09-08 22:51:46 -04:00
|
|
|
import { featureFlags } from '$lib/stores/server-config.store';
|
2024-02-14 06:38:57 -08:00
|
|
|
import { oauth } from '$lib/utils';
|
2024-05-26 18:15:52 -04:00
|
|
|
import { type UserAdminResponseDto } from '@immich/sdk';
|
2025-09-16 16:22:13 -04:00
|
|
|
import { Button, LoadingSpinner } from '@immich/ui';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { onMount } from 'svelte';
|
2025-09-16 16:22:13 -04:00
|
|
|
import { t } from 'svelte-i18n';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { fade } from 'svelte/transition';
|
|
|
|
|
import { handleError } from '../../utils/handle-error';
|
|
|
|
|
import { notificationController, NotificationType } from '../shared-components/notification/notification';
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
user: UserAdminResponseDto;
|
|
|
|
|
}
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let { user = $bindable() }: Props = $props();
|
|
|
|
|
|
|
|
|
|
let loading = $state(true);
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
onMount(async () => {
|
2024-12-18 15:19:48 +01:00
|
|
|
if (oauth.isCallback(globalThis.location)) {
|
2023-07-01 00:50:47 -04:00
|
|
|
try {
|
|
|
|
|
loading = true;
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2024-12-18 15:19:48 +01:00
|
|
|
user = await oauth.link(globalThis.location);
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
notificationController.show({
|
2024-06-04 21:53:00 +02:00
|
|
|
message: $t('linked_oauth_account'),
|
2023-07-01 00:50:47 -04:00
|
|
|
type: NotificationType.Info,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
2024-06-12 12:54:40 +02:00
|
|
|
handleError(error, $t('errors.unable_to_link_oauth_account'));
|
2023-07-01 00:50:47 -04:00
|
|
|
} finally {
|
2024-02-27 08:37:37 -08:00
|
|
|
await goto('?open=oauth');
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
}
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
loading = false;
|
|
|
|
|
});
|
2022-12-26 10:35:52 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleUnlink = async () => {
|
|
|
|
|
try {
|
2024-02-13 17:07:37 -05:00
|
|
|
user = await oauth.unlink();
|
2023-07-01 00:50:47 -04:00
|
|
|
notificationController.show({
|
2024-06-04 21:53:00 +02:00
|
|
|
message: $t('unlinked_oauth_account'),
|
2023-07-01 00:50:47 -04:00
|
|
|
type: NotificationType.Info,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
2024-06-04 21:53:00 +02:00
|
|
|
handleError(error, $t('errors.unable_to_unlink_account'));
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
};
|
2022-12-26 10:35:52 -05:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<section class="my-4">
|
2023-07-01 00:50:47 -04:00
|
|
|
<div in:fade={{ duration: 500 }}>
|
|
|
|
|
<div class="flex justify-end">
|
|
|
|
|
{#if loading}
|
2023-07-18 13:19:39 -05:00
|
|
|
<div class="flex place-content-center place-items-center">
|
2023-07-01 00:50:47 -04:00
|
|
|
<LoadingSpinner />
|
|
|
|
|
</div>
|
2023-09-01 07:08:42 -04:00
|
|
|
{:else if $featureFlags.oauth}
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if user.oauthId}
|
2025-03-12 16:56:55 -04:00
|
|
|
<Button shape="round" size="small" onclick={() => handleUnlink()}>{$t('unlink_oauth')}</Button>
|
2023-07-01 00:50:47 -04:00
|
|
|
{:else}
|
2025-03-12 16:56:55 -04:00
|
|
|
<Button shape="round" size="small" onclick={() => oauth.authorize(globalThis.location)}
|
|
|
|
|
>{$t('link_to_oauth')}</Button
|
|
|
|
|
>
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-12-26 10:35:52 -05:00
|
|
|
</section>
|