[CORL-474] Harmonize SSO User ID's (#2440)

* feat: harmonized user id's

* fix: doctoc
This commit is contained in:
Wyatt Johnson
2019-08-01 21:30:33 +00:00
committed by Kim Gardner
parent 3d9c94d36a
commit 1c5c82286e
3 changed files with 15 additions and 6 deletions
@@ -125,6 +125,7 @@ export async function findOrCreateSSOUser(
mongo,
tenant,
{
id,
username,
role: GQLUSER_ROLE.COMMENTER,
email,
+4 -6
View File
@@ -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,
};
+10
View File
@@ -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);