mirror of
https://github.com/wassname/talk.git
synced 2026-07-10 20:54:12 +08:00
[CORL-474] Harmonize SSO User ID's (#2440)
* feat: harmonized user id's * fix: doctoc
This commit is contained in:
committed by
Kim Gardner
parent
3d9c94d36a
commit
1c5c82286e
@@ -125,6 +125,7 @@ export async function findOrCreateSSOUser(
|
||||
mongo,
|
||||
tenant,
|
||||
{
|
||||
id,
|
||||
username,
|
||||
role: GQLUSER_ROLE.COMMENTER,
|
||||
email,
|
||||
|
||||
@@ -374,21 +374,18 @@ export type InsertUserInput = Omit<
|
||||
| "ignoredUsers"
|
||||
| "emailVerificationID"
|
||||
| "createdAt"
|
||||
>;
|
||||
> &
|
||||
Partial<Pick<User, "id">>;
|
||||
|
||||
export async function insertUser(
|
||||
mongo: Db,
|
||||
tenantID: string,
|
||||
input: InsertUserInput,
|
||||
{ id = uuid.v4(), ...input }: InsertUserInput,
|
||||
now = new Date()
|
||||
) {
|
||||
// Create a new ID for the user.
|
||||
const id = uuid.v4();
|
||||
|
||||
// default are the properties set by the application when a new user is
|
||||
// created.
|
||||
const defaults: Sub<User, InsertUserInput> = {
|
||||
id,
|
||||
tenantID,
|
||||
tokens: [],
|
||||
ignoredUsers: [],
|
||||
@@ -425,6 +422,7 @@ export async function insertUser(
|
||||
const user: Readonly<User> = {
|
||||
...defaults,
|
||||
...input,
|
||||
id,
|
||||
profiles,
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Db } from "mongodb";
|
||||
|
||||
import {
|
||||
DuplicateEmailError,
|
||||
DuplicateUserError,
|
||||
EmailAlreadySetError,
|
||||
EmailNotSetError,
|
||||
LocalProfileAlreadySetError,
|
||||
@@ -85,6 +86,15 @@ export async function insert(
|
||||
}
|
||||
}
|
||||
|
||||
if (input.id) {
|
||||
// Try to check to see if there is a user with the same ID before we try to
|
||||
// create the user again.
|
||||
const alreadyFoundUser = await retrieveUser(mongo, tenant.id, input.id);
|
||||
if (alreadyFoundUser) {
|
||||
throw new DuplicateUserError();
|
||||
}
|
||||
}
|
||||
|
||||
const localProfile = getLocalProfile(input);
|
||||
if (localProfile) {
|
||||
validateEmail(localProfile.id);
|
||||
|
||||
Reference in New Issue
Block a user