This commit is contained in:
Eric van der Vlist 2023-02-26 18:10:33 +01:00
parent 57e0b32082
commit 2c6107d761
2 changed files with 14 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import { adminCredentials } from '../credentials';
import { put } from '~/lib/put'; import { put } from '~/lib/put';
import { del } from '~/lib/del'; import { del } from '~/lib/del';
import { isFunction } from 'lodash'; import { isFunction } from 'lodash';
import { userId } from '~/lib/user-id';
interface Props { interface Props {
values?: () => any; values?: () => any;
@ -33,7 +34,7 @@ const User: Component<Props> = (props) => {
values, values,
context, context,
}); });
const id = getValues()?._id ?? `user:${uuid()}`; const id = getValues()?._id ?? userId(values.username, values.database);
await put(id, values, isNew()); await put(id, values, isNew());
const couchUserId = `org.couchdb.user:${values.username}`; const couchUserId = `org.couchdb.user:${values.username}`;
const userDoc = { const userDoc = {

12
src/lib/user-id.ts Normal file
View File

@ -0,0 +1,12 @@
export const userId = (username: string, database: string) => {
const dbUrl = new URL(database);
return `@${username}>${dbUrl.hostname}`;
};
export const parseUserId = (id: string) => {
const matches = id.match(/^@([^>]+)>(.+)$/);
if (!matches) {
return null;
}
return { username: matches[1], hostname: matches[2] };
};