21 lines
475 B
TypeScript
21 lines
475 B
TypeScript
import { isEmail } from "class-validator"
|
|
import { MedusaError } from "medusa-core-utils"
|
|
|
|
/**
|
|
* Used to validate user email.
|
|
* @param {string} email - email to validate
|
|
* @return {string} the validated email
|
|
*/
|
|
export function validateEmail(email: string): string {
|
|
const validatedEmail = isEmail(email)
|
|
|
|
if (!validatedEmail) {
|
|
throw new MedusaError(
|
|
MedusaError.Types.INVALID_DATA,
|
|
"The email is not valid"
|
|
)
|
|
}
|
|
|
|
return email.toLowerCase()
|
|
}
|