fix(server): Allow passwordless users when oauth enabled (#13517)

* fix(server): Allow passwordless users when oauth enabled

* fix(web): Use features flags for checking oauth
This commit is contained in:
jedi04 2024-10-17 21:54:50 +05:30 committed by GitHub
parent 3f663106e8
commit bb694aeeeb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 4 deletions

View File

@ -62,7 +62,6 @@ export class UserAdminCreateDto {
@Transform(toEmail)
email!: string;
@IsNotEmpty()
@IsString()
password!: string;

View File

@ -26,6 +26,10 @@ export class UserAdminService extends BaseService {
async create(dto: UserAdminCreateDto): Promise<UserAdminResponseDto> {
const { notify, ...rest } = dto;
const config = await this.getConfig({ withCache: false });
if (!config.oauth.enabled && !rest.password) {
throw new BadRequestException('password is required');
}
const user = await createUser({ userRepo: this.userRepository, cryptoRepo: this.cryptoRepository }, rest);
await this.eventRepository.emit('user.signup', {

View File

@ -13,6 +13,7 @@
export let onClose: () => void;
export let onSubmit: () => void;
export let onCancel: () => void;
export let oauthEnabled = false;
let error: string;
let success: string;
@ -90,12 +91,17 @@
<div class="my-4 flex flex-col gap-2">
<label class="immich-form-label" for="password">{$t('password')}</label>
<PasswordField id="password" bind:password autocomplete="new-password" />
<PasswordField id="password" bind:password autocomplete="new-password" required={!oauthEnabled} />
</div>
<div class="my-4 flex flex-col gap-2">
<label class="immich-form-label" for="confirmPassword">{$t('confirm_password')}</label>
<PasswordField id="confirmPassword" bind:password={confirmPassword} autocomplete="new-password" />
<PasswordField
id="confirmPassword"
bind:password={confirmPassword}
autocomplete="new-password"
required={!oauthEnabled}
/>
</div>
<div class="my-4 flex place-items-center justify-between gap-2">

View File

@ -15,7 +15,7 @@
notificationController,
} from '$lib/components/shared-components/notification/notification';
import { locale } from '$lib/stores/preferences.store';
import { serverConfig } from '$lib/stores/server-config.store';
import { serverConfig, featureFlags } from '$lib/stores/server-config.store';
import { user } from '$lib/stores/user.store';
import { websocketEvents } from '$lib/stores/websocket';
import { copyToClipboard } from '$lib/utils';
@ -113,6 +113,7 @@
onSubmit={onUserCreated}
onCancel={() => (shouldShowCreateUserForm = false)}
onClose={() => (shouldShowCreateUserForm = false)}
oauthEnabled={$featureFlags.oauth}
/>
{/if}