👔 (necktie) add safeguard for duplicate email case
Create a safeguard so that when a user enters an email address that has already been used with another OAuth provider, it will be rejected to avoid double entries.
This commit is contained in:
@ -5,6 +5,7 @@ import { createUserSessionService } from "../../../userSession/services/createUs
|
|||||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||||
import { createUserViaOauth } from "../../../user/user.types";
|
import { createUserViaOauth } from "../../../user/user.types";
|
||||||
import { createUserService } from "../../../user/services/internal/createUser.service";
|
import { createUserService } from "../../../user/services/internal/createUser.service";
|
||||||
|
import { AppError } from "../../../../helpers/error/instances/app";
|
||||||
|
|
||||||
export const OAuthUserProvisionService = async (
|
export const OAuthUserProvisionService = async (
|
||||||
payload: createUserViaOauth,
|
payload: createUserViaOauth,
|
||||||
@ -21,6 +22,15 @@ export const OAuthUserProvisionService = async (
|
|||||||
if (findUserResult) {
|
if (findUserResult) {
|
||||||
return await createUserSessionService(findUserResult.id, userHeaderInfo);
|
return await createUserSessionService(findUserResult.id, userHeaderInfo);
|
||||||
} else {
|
} else {
|
||||||
|
const findUserByEmailOnly = await findUserService({
|
||||||
|
identifier: payload.email,
|
||||||
|
queryTarget: "email",
|
||||||
|
options: { verbosity: "exist" },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (findUserByEmailOnly)
|
||||||
|
throw new AppError(409, "Email already in use with another account");
|
||||||
|
|
||||||
const createdUser = await createUserService(payload);
|
const createdUser = await createUserService(payload);
|
||||||
return await createUserSessionService(createdUser.id, userHeaderInfo);
|
return await createUserSessionService(createdUser.id, userHeaderInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user