Optimize forgot-password whatsapp number matching and automatic DDI 55 prefix injection
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 1m4s
Details
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 1m4s
Details
This commit is contained in:
parent
b6a57c6f00
commit
a4f42a31ec
28
server.ts
28
server.ts
|
|
@ -248,9 +248,26 @@ app.post('/api/auth/forgot-password', async (req: Request, res: Response) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const user = await prisma.user.findFirst({
|
let user;
|
||||||
where: channel === 'whatsapp' ? { whatsapp: identifier } : { email: identifier.toLowerCase() }
|
if (channel === 'whatsapp') {
|
||||||
|
const cleanIdentifier = identifier.replace(/\D/g, '');
|
||||||
|
const numberWithoutDDI = cleanIdentifier.replace(/^55/, '');
|
||||||
|
const numberWithDDI = '55' + numberWithoutDDI;
|
||||||
|
|
||||||
|
user = await prisma.user.findFirst({
|
||||||
|
where: {
|
||||||
|
OR: [
|
||||||
|
{ whatsapp: cleanIdentifier },
|
||||||
|
{ whatsapp: numberWithoutDDI },
|
||||||
|
{ whatsapp: numberWithDDI }
|
||||||
|
]
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
user = await prisma.user.findFirst({
|
||||||
|
where: { email: identifier.toLowerCase() }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
res.json({ success: true, message: 'Se o usuário existir, o link foi enviado.' });
|
res.json({ success: true, message: 'Se o usuário existir, o link foi enviado.' });
|
||||||
|
|
@ -1342,9 +1359,14 @@ export async function sendWhatsappNotification(phone: string, text: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean phone number (leave only digits)
|
// Clean phone number (leave only digits)
|
||||||
const cleanPhone = phone.replace(/\D/g, '');
|
let cleanPhone = phone.replace(/\D/g, '');
|
||||||
if (!cleanPhone) return false;
|
if (!cleanPhone) return false;
|
||||||
|
|
||||||
|
// Add DDI 55 for Brazil if not present
|
||||||
|
if (cleanPhone.length === 10 || cleanPhone.length === 11) {
|
||||||
|
cleanPhone = '55' + cleanPhone;
|
||||||
|
}
|
||||||
|
|
||||||
const apiUrl = settings.evolutionApiUrl.replace(/\/$/, '');
|
const apiUrl = settings.evolutionApiUrl.replace(/\/$/, '');
|
||||||
const instance = settings.evolutionInstance || 'microtecflix';
|
const instance = settings.evolutionInstance || 'microtecflix';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue