User ids
This commit is contained in:
parent
57e0b32082
commit
2c6107d761
|
@ -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 = {
|
||||||
|
|
|
@ -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] };
|
||||||
|
};
|
Loading…
Reference in New Issue