fix: password being reset when editing urls (#872)

This commit is contained in:
diced
2025-09-02 15:53:56 -07:00
parent 003dba9ce4
commit a92f072d62
3 changed files with 11 additions and 6 deletions

View File

@@ -18,10 +18,10 @@ export default function EditUrlModal({
if (!url) return null;
const [maxViews, setMaxViews] = useState<number | null>(url?.maxViews ?? null);
const [password, setPassword] = useState<string | null>('');
const [vanity, setVanity] = useState<string | null>(url?.vanity ?? null);
const [destination, setDestination] = useState<string | null>(url?.destination ?? null);
const [enabled, setEnabled] = useState<boolean>(url?.enabled ?? true);
const [password, setPassword] = useState<string | null>('');
const handleRemovePassword = async () => {
if (!url.password) return;

View File

@@ -3,3 +3,11 @@ import type { Url as PrismaUrl } from '@/prisma/client';
export type Url = PrismaUrl & {
similarity?: number;
};
export function cleanUrlPasswords(urls: Url[]) {
for (const url of urls) {
(url as any).password = !!url.password;
}
return urls;
}

View File

@@ -2,7 +2,7 @@ import { config } from '@/lib/config';
import { hashPassword } from '@/lib/crypto';
import { randomCharacters } from '@/lib/random';
import { prisma } from '@/lib/db';
import { Url } from '@/lib/db/models/url';
import { cleanUrlPasswords, Url } from '@/lib/db/models/url';
import { log } from '@/lib/logger';
import { z } from 'zod';
import { onShorten } from '@/lib/webhooks';
@@ -173,12 +173,9 @@ export default fastifyPlugin(
where: {
userId: req.user.id,
},
omit: {
password: true,
},
});
return res.send(urls);
return res.send(cleanUrlPasswords(urls));
});
done();