feat: lock auth session (#18322)
This commit is contained in:
@@ -3,9 +3,8 @@
|
||||
import AuthPageLayout from '$lib/components/layouts/AuthPageLayout.svelte';
|
||||
import PinCodeCreateForm from '$lib/components/user-settings-page/PinCodeCreateForm.svelte';
|
||||
import PincodeInput from '$lib/components/user-settings-page/PinCodeInput.svelte';
|
||||
import { AppRoute } from '$lib/constants';
|
||||
import { handleError } from '$lib/utils/handle-error';
|
||||
import { verifyPinCode } from '@immich/sdk';
|
||||
import { unlockAuthSession } from '@immich/sdk';
|
||||
import { Icon } from '@immich/ui';
|
||||
import { mdiLockOpenVariantOutline, mdiLockOutline, mdiLockSmart } from '@mdi/js';
|
||||
import { t } from 'svelte-i18n';
|
||||
@@ -23,17 +22,15 @@
|
||||
let hasPinCode = $derived(data.hasPinCode);
|
||||
let pinCode = $state('');
|
||||
|
||||
const onPinFilled = async (code: string, withDelay = false) => {
|
||||
const handleUnlockSession = async (code: string) => {
|
||||
try {
|
||||
await verifyPinCode({ pinCodeSetupDto: { pinCode: code } });
|
||||
await unlockAuthSession({ sessionUnlockDto: { pinCode: code } });
|
||||
|
||||
isVerified = true;
|
||||
|
||||
if (withDelay) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
void goto(data.continuePath ?? AppRoute.LOCKED);
|
||||
await goto(data.continueUrl);
|
||||
} catch (error) {
|
||||
handleError(error, $t('wrong_pin_code'));
|
||||
isBadPinCode = true;
|
||||
@@ -64,7 +61,7 @@
|
||||
bind:value={pinCode}
|
||||
tabindexStart={1}
|
||||
pinLength={6}
|
||||
onFilled={(pinCode) => onPinFilled(pinCode, true)}
|
||||
onFilled={handleUnlockSession}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { AppRoute } from '$lib/constants';
|
||||
import { authenticate } from '$lib/utils/auth';
|
||||
import { getFormatter } from '$lib/utils/i18n';
|
||||
import { getAuthStatus } from '@immich/sdk';
|
||||
@@ -8,8 +9,6 @@ export const load = (async ({ url }) => {
|
||||
|
||||
const { pinCode } = await getAuthStatus();
|
||||
|
||||
const continuePath = url.searchParams.get('continue');
|
||||
|
||||
const $t = await getFormatter();
|
||||
|
||||
return {
|
||||
@@ -17,6 +16,6 @@ export const load = (async ({ url }) => {
|
||||
title: $t('pin_verification'),
|
||||
},
|
||||
hasPinCode: !!pinCode,
|
||||
continuePath,
|
||||
continueUrl: url.searchParams.get('continue') || AppRoute.LOCKED,
|
||||
};
|
||||
}) satisfies PageLoad;
|
||||
|
||||
Reference in New Issue
Block a user