detect disposable email addresses
This commit is contained in:
parent
bd06ee7bf2
commit
8a019f58b7
@ -3,28 +3,37 @@ import { registerUserSchema } from '$lib/schemas';
|
|||||||
import { validateData } from '$lib/utils';
|
import { validateData } from '$lib/utils';
|
||||||
|
|
||||||
|
|
||||||
async function checkDisposableEmail(email:string) {
|
async function checkDisposableEmail(email) {
|
||||||
|
const url = `https://disposable.debounce.io/?email=${encodeURIComponent(email)}`;
|
||||||
}const url = `https://disposable.debounce.io/?email=${encodeURIComponent(email)}`;
|
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const output = (await response.json())?.disposable ?? false;
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
register: async ({ locals, request }) => {
|
register: async ({ locals, request }) => {
|
||||||
const { formData, errors } = await validateData(await request.formData(), registerUserSchema);
|
|
||||||
|
|
||||||
|
|
||||||
|
const { formData, errors } = await validateData(await request.formData(), registerUserSchema);
|
||||||
if (errors) {
|
if (errors) {
|
||||||
|
console.log(errors.fieldErrors)
|
||||||
return fail(400, {
|
return fail(400, {
|
||||||
data: formData,
|
data: formData,
|
||||||
errors: errors.fieldErrors
|
errors: errors.fieldErrors
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(formData)
|
const isEmailDisposable = await checkDisposableEmail(formData?.email);
|
||||||
//await checkDisposableEmail()
|
|
||||||
|
if(isEmailDisposable === "true") {
|
||||||
|
error(400, 'Disposable Email Addresses not allowed!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//let username = generateUsername(formData.name.split(' ').join('')).toLowerCase();
|
//let username = generateUsername(formData.name.split(' ').join('')).toLowerCase();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user