From 49607f484f35da7ed13d201c3513ae2efffa338a Mon Sep 17 00:00:00 2001 From: DanielS Date: Wed, 24 Jun 2026 23:56:52 +0200 Subject: [PATCH] Add email send to password reset --- shop/lib/actions/users.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/shop/lib/actions/users.ts b/shop/lib/actions/users.ts index efa6769..2901f12 100644 --- a/shop/lib/actions/users.ts +++ b/shop/lib/actions/users.ts @@ -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: `

Klicken Sie hier, um Ihr Passwort zurückzusetzen.

`, + }); +} const admin = createAdminClient() // Generate a reset link or send email const { error } = await admin.auth.admin.generateLink({