Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this just allows empty strings, but it should probably have Optional({ nullable: true }) and still keep the is not empty. We should also test that you cannot login with an empty string of password login is enabled still

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have set password to be string in the user entity. So would it be okay to insert null values?

password?: string;

And during login we have added check for not allowing empty password

if (!user || !user.password) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah null values would be preferred over empty strings IMO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see that we don't allow null in the database. We can change that later I think. We'll allow empty now, and move to null in the future.

@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
Loading