Skip to content

Commit

Permalink
fix(server): Allow passwordless users when oauth enabled (immich-app#…
Browse files Browse the repository at this point in the history
…13517)

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

* fix(web): Use features flags for checking oauth
  • Loading branch information
jedi04 authored and yosit committed Oct 17, 2024
1 parent 499e2e0 commit 39af018
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion server/src/dtos/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class UserAdminCreateDto {
@Transform(toEmail)
email!: string;

@IsNotEmpty()
@IsString()
password!: string;

Expand Down
4 changes: 4 additions & 0 deletions server/src/services/user-admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
10 changes: 8 additions & 2 deletions web/src/lib/components/forms/create-user-form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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">
Expand Down
3 changes: 2 additions & 1 deletion web/src/routes/admin/user-management/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -113,6 +113,7 @@
onSubmit={onUserCreated}
onCancel={() => (shouldShowCreateUserForm = false)}
onClose={() => (shouldShowCreateUserForm = false)}
oauthEnabled={$featureFlags.oauth}
/>
{/if}

Expand Down

0 comments on commit 39af018

Please sign in to comment.