mirror of
https://github.com/KevinMidboe/immich.git
synced 2026-01-16 06:06:20 +00:00
Migrate SvelteKit to the latest version 431 (#526)
This commit is contained in:
25
web/src/routes/auth/change-password/+page.svelte
Normal file
25
web/src/routes/auth/change-password/+page.svelte
Normal file
@@ -0,0 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { fade } from 'svelte/transition';
|
||||
|
||||
import ChangePasswordForm from '$lib/components/forms/change-password-form.svelte';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
const onSuccessHandler = async () => {
|
||||
await fetch('auth/logout', { method: 'POST' });
|
||||
|
||||
goto('/auth/login');
|
||||
};
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Change Password - Immich</title>
|
||||
</svelte:head>
|
||||
|
||||
<section class="h-screen w-screen flex place-items-center place-content-center">
|
||||
<div in:fade={{ duration: 100 }} out:fade={{ duration: 100 }}>
|
||||
<ChangePasswordForm user={data.user} on:success={onSuccessHandler} />
|
||||
</div>
|
||||
</section>
|
||||
21
web/src/routes/auth/change-password/+page.ts
Normal file
21
web/src/routes/auth/change-password/+page.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { api } from '@api';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
export const prerender = false;
|
||||
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
export const load: PageLoad = async () => {
|
||||
try {
|
||||
const { data: userInfo } = await api.userApi.getMyUserInfo();
|
||||
|
||||
if (userInfo.shouldChangePassword) {
|
||||
return {
|
||||
user: userInfo
|
||||
};
|
||||
} else {
|
||||
throw redirect(302, '/photos');
|
||||
}
|
||||
} catch (e) {
|
||||
throw redirect(302, '/auth/login');
|
||||
}
|
||||
};
|
||||
@@ -1,56 +0,0 @@
|
||||
<script context="module" lang="ts">
|
||||
export const prerender = false;
|
||||
|
||||
import type { Load } from '@sveltejs/kit';
|
||||
|
||||
export const load: Load = async () => {
|
||||
try {
|
||||
const { data: userInfo } = await api.userApi.getMyUserInfo();
|
||||
|
||||
if (userInfo.shouldChangePassword) {
|
||||
return {
|
||||
status: 200,
|
||||
props: {
|
||||
user: userInfo
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/photos'
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/auth/login'
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { fade } from 'svelte/transition';
|
||||
|
||||
import ChangePasswordForm from '$lib/components/forms/change-password-form.svelte';
|
||||
import { api, UserResponseDto } from '@api';
|
||||
|
||||
export let user: UserResponseDto;
|
||||
|
||||
const onSuccessHandler = async () => {
|
||||
await fetch('auth/logout', { method: 'POST' });
|
||||
|
||||
goto('/auth/login');
|
||||
};
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Change Password - Immich</title>
|
||||
</svelte:head>
|
||||
|
||||
<section class="h-screen w-screen flex place-items-center place-content-center">
|
||||
<div in:fade={{ duration: 100 }} out:fade={{ duration: 100 }}>
|
||||
<ChangePasswordForm {user} on:success={onSuccessHandler} />
|
||||
</div>
|
||||
</section>
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import LoginForm from '$lib/components/forms/login-form.svelte';
|
||||
|
||||
const onLoginSuccess = async () => {
|
||||
const onLoginSuccess = () => {
|
||||
goto('/photos');
|
||||
};
|
||||
</script>
|
||||
@@ -1,19 +0,0 @@
|
||||
import { api, serverApi } from '@api';
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
|
||||
export const POST: RequestHandler = async () => {
|
||||
api.removeAccessToken();
|
||||
serverApi.removeAccessToken();
|
||||
|
||||
return {
|
||||
headers: {
|
||||
'Set-Cookie': [
|
||||
'immich_is_authenticated=deleted; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT;',
|
||||
'immich_access_token=delete; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT'
|
||||
]
|
||||
},
|
||||
body: {
|
||||
ok: true
|
||||
}
|
||||
};
|
||||
};
|
||||
27
web/src/routes/auth/logout/+server.ts
Normal file
27
web/src/routes/auth/logout/+server.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { api, serverApi } from '@api';
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
|
||||
export const POST: RequestHandler = async () => {
|
||||
api.removeAccessToken();
|
||||
serverApi.removeAccessToken();
|
||||
|
||||
const headers = new Headers();
|
||||
|
||||
headers.append(
|
||||
'set-cookie',
|
||||
'immich_is_authenticated=deleted; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT;'
|
||||
);
|
||||
headers.append(
|
||||
'set-cookie',
|
||||
'immich_access_token=delete; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT'
|
||||
);
|
||||
return json(
|
||||
{
|
||||
ok: true
|
||||
},
|
||||
{
|
||||
headers
|
||||
}
|
||||
);
|
||||
};
|
||||
13
web/src/routes/auth/register/+page.server.ts
Normal file
13
web/src/routes/auth/register/+page.server.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { serverApi } from '@api';
|
||||
|
||||
export const load: PageServerLoad = async () => {
|
||||
const { data } = await serverApi.userApi.getUserCount();
|
||||
if (data.userCount != 0) {
|
||||
// Admin has been registered, redirect to login
|
||||
throw redirect(302, '/auth/login');
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
11
web/src/routes/auth/register/+page.svelte
Normal file
11
web/src/routes/auth/register/+page.svelte
Normal file
@@ -0,0 +1,11 @@
|
||||
<script lang="ts">
|
||||
import AdminRegistrationForm from '$lib/components/forms/admin-registration-form.svelte';
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Admin Registration - Immich</title>
|
||||
</svelte:head>
|
||||
|
||||
<section class="h-screen w-screen flex place-items-center place-content-center">
|
||||
<AdminRegistrationForm />
|
||||
</section>
|
||||
@@ -1,31 +0,0 @@
|
||||
<script context="module" lang="ts">
|
||||
import type { Load } from '@sveltejs/kit';
|
||||
|
||||
export const load: Load = async () => {
|
||||
const { data } = await api.userApi.getUserCount();
|
||||
if (data.userCount != 0) {
|
||||
// Admin has been registered, redirect to login
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/auth/login'
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
status: 200
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import AdminRegistrationForm from '$lib/components/forms/admin-registration-form.svelte';
|
||||
import { api } from '@api';
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Admin Registration - Immich</title>
|
||||
</svelte:head>
|
||||
|
||||
<section class="h-screen w-screen flex place-items-center place-content-center">
|
||||
<AdminRegistrationForm />
|
||||
</section>
|
||||
Reference in New Issue
Block a user