mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
feat: manage link token via cookie instead
This commit is contained in:
@@ -51,7 +51,7 @@ export const Docs = {
|
||||
export const Route = {
|
||||
// auth
|
||||
login: (params?: { continue?: string; autoLaunch?: 0 | 1 }) => '/auth/login' + asQueryString(params),
|
||||
authLink: (params?: { oauthLinkToken?: string; email?: string }) => '/auth/link' + asQueryString(params),
|
||||
authLink: (params?: { email?: string }) => '/auth/link' + asQueryString(params),
|
||||
logout: (params?: { continue?: string }) => '/auth/logout' + asQueryString(params),
|
||||
register: () => '/auth/register',
|
||||
changePassword: () => '/auth/change-password',
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
import { getServerErrorMessage } from '$lib/utils/handle-error';
|
||||
import { login } from '@immich/sdk';
|
||||
import { Alert, Button, Field, Input, PasswordInput, Stack, toastManager } from '@immich/ui';
|
||||
import { onMount } from 'svelte';
|
||||
import { t } from 'svelte-i18n';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
@@ -18,22 +17,17 @@
|
||||
|
||||
let { data }: Props = $props();
|
||||
|
||||
let oauthLinkToken = $state(data.oauthLinkToken);
|
||||
let email = $state(data.email || authManager.user?.email || '');
|
||||
let password = $state('');
|
||||
let errorMessage = $state('');
|
||||
let loading = $state(false);
|
||||
|
||||
onMount(async () => {
|
||||
await goto(Route.authLink(), { replaceState: true });
|
||||
});
|
||||
|
||||
const handleSubmit = async (event: Event) => {
|
||||
event.preventDefault();
|
||||
try {
|
||||
errorMessage = '';
|
||||
loading = true;
|
||||
const user = await login({ loginCredentialDto: { email, password, oauthLinkToken } });
|
||||
const user = await login({ loginCredentialDto: { email, password } });
|
||||
eventManager.emit('AuthLogin', user);
|
||||
await authManager.refresh();
|
||||
toastManager.primary($t('linked_oauth_account'));
|
||||
|
||||
@@ -2,7 +2,6 @@ import { getFormatter } from '$lib/utils/i18n';
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
export const load = (async ({ url }) => {
|
||||
const oauthLinkToken = url.searchParams.get('oauthLinkToken') || '';
|
||||
const email = url.searchParams.get('email') || '';
|
||||
|
||||
const $t = await getFormatter();
|
||||
@@ -10,7 +9,6 @@ export const load = (async ({ url }) => {
|
||||
meta: {
|
||||
title: $t('link_to_oauth'),
|
||||
},
|
||||
oauthLinkToken,
|
||||
email,
|
||||
};
|
||||
}) satisfies PageLoad;
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
} catch (error) {
|
||||
if (isHttpError(error) && error.data?.message === 'oauth_account_link_required') {
|
||||
const errorData = error.data as unknown as Record<string, string>;
|
||||
await goto(Route.authLink({ oauthLinkToken: errorData.oauthLinkToken, email: errorData.userEmail }));
|
||||
await goto(Route.authLink({ email: errorData.userEmail }));
|
||||
return;
|
||||
}
|
||||
console.error('Error [login-form] [oauth.callback]', error);
|
||||
|
||||
Reference in New Issue
Block a user