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