Add email send to password reset
Some checks failed
Staging Build / build (push) Failing after 25s

This commit is contained in:
DanielS
2026-06-24 23:56:52 +02:00
parent 2120698192
commit 49607f484f

View File

@@ -1,7 +1,8 @@
'use server'
import { createAdminClient } from '@/lib/supabase/admin'
import { revalidatePath } from 'next/cache'
import { revalidatePath } from 'next/cache';
import { sendMail } from '@/utils/mail';
export async function getUsers() {
const admin = createAdminClient()
@@ -79,6 +80,23 @@ export async function updateUserStatus(id: string, ban: boolean) {
}
export async function resetPassword(email: string) {
const admin = createAdminClient();
// Generate password recovery link
const { data, error } = await admin.auth.admin.generateLink({
type: 'recovery',
email,
});
if (error) throw error;
const resetLink = data?.action_link || data?.link || '';
if (!resetLink) throw new Error('Reset link not generated');
// Send email via configured SMTP
await sendMail({
to: email,
subject: 'Passwort zurücksetzen',
text: `Klicken Sie auf den folgenden Link, um Ihr Passwort zurückzusetzen: ${resetLink}`,
html: `<p>Klicken Sie <a href="${resetLink}">hier</a>, um Ihr Passwort zurückzusetzen.</p>`,
});
}
const admin = createAdminClient()
// Generate a reset link or send email
const { error } = await admin.auth.admin.generateLink({