fix(server): require local admin account (#1070)

This commit is contained in:
Jason Rasmussen
2022-12-09 15:53:11 -05:00
committed by GitHub
parent 3bb103c6b6
commit 14889e7d85
14 changed files with 119 additions and 38 deletions

View File

@@ -1,12 +1,5 @@
<script lang="ts">
import { goto } from '$app/navigation';
import type { PageData } from './$types';
export let data: PageData;
async function onGettingStartedClicked() {
data.isAdminUserExist ? await goto('/auth/login') : await goto('/auth/register');
}
</script>
<svelte:head>
@@ -26,7 +19,7 @@
</h1>
<button
class="border px-4 py-4 rounded-md bg-immich-primary dark:bg-immich-dark-primary dark:text-immich-dark-gray dark:border-immich-dark-gray hover:bg-immich-primary/75 text-white font-bold w-[200px]"
on:click={onGettingStartedClicked}
on:click={() => goto('/auth/login')}
>Getting Started
</button>
</div>

View File

@@ -1,20 +1,10 @@
export const prerender = false;
import { redirect } from '@sveltejs/kit';
import { api } from '@api';
import type { PageLoad } from './$types';
import { browser } from '$app/environment';
export const load: PageLoad = async ({ parent }) => {
const { user } = await parent();
if (user) {
throw redirect(302, '/photos');
}
if (browser) {
const { data } = await api.userApi.getUserCount();
return {
isAdminUserExist: data.userCount != 0
};
}
};

View 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(true);
if (data.userCount === 0) {
// Admin not registered
throw redirect(302, '/auth/register');
}
return;
};

View File

@@ -3,7 +3,7 @@ import type { PageServerLoad } from './$types';
import { serverApi } from '@api';
export const load: PageServerLoad = async () => {
const { data } = await serverApi.userApi.getUserCount();
const { data } = await serverApi.userApi.getUserCount(true);
if (data.userCount != 0) {
// Admin has been registered, redirect to login
throw redirect(302, '/auth/login');