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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 119 additions and 38 deletions

View file

@ -6108,10 +6108,11 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
},
/**
*
* @param {boolean} [admin]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getUserCount: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
getUserCount: async (admin?: boolean, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/user/count`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
@ -6124,6 +6125,10 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
if (admin !== undefined) {
localVarQueryParameter['admin'] = admin;
}
setSearchParams(localVarUrlObj, localVarQueryParameter);
@ -6292,11 +6297,12 @@ export const UserApiFp = function(configuration?: Configuration) {
},
/**
*
* @param {boolean} [admin]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getUserCount(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<UserCountResponseDto>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getUserCount(options);
async getUserCount(admin?: boolean, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<UserCountResponseDto>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getUserCount(admin, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
@ -6393,11 +6399,12 @@ export const UserApiFactory = function (configuration?: Configuration, basePath?
},
/**
*
* @param {boolean} [admin]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getUserCount(options?: any): AxiosPromise<UserCountResponseDto> {
return localVarFp.getUserCount(options).then((request) => request(axios, basePath));
getUserCount(admin?: boolean, options?: any): AxiosPromise<UserCountResponseDto> {
return localVarFp.getUserCount(admin, options).then((request) => request(axios, basePath));
},
/**
*
@ -6505,12 +6512,13 @@ export class UserApi extends BaseAPI {
/**
*
* @param {boolean} [admin]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof UserApi
*/
public getUserCount(options?: AxiosRequestConfig) {
return UserApiFp(this.configuration).getUserCount(options).then((request) => request(this.axios, this.basePath));
public getUserCount(admin?: boolean, options?: AxiosRequestConfig) {
return UserApiFp(this.configuration).getUserCount(admin, options).then((request) => request(this.axios, this.basePath));
}
/**

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');