mirror of
https://github.com/Since-3/since3-portal.git
synced 2026-10-12 21:41:16 +00:00
added email delivery for Account creation, Invoices, Credentials Creation
This commit is contained in:
parent
96208249aa
commit
14e1f03b66
19 changed files with 697 additions and 43 deletions
|
|
@ -2,6 +2,9 @@
|
|||
import { createAdminClient } from "@/lib/supabase/admin";
|
||||
import { verifySession } from "@/lib/supabase/dal";
|
||||
import { generatePassword } from "@/lib/generate-password";
|
||||
import { getAppUrl } from "@/modules/shared/mail/app-url";
|
||||
import { sendMail } from "@/modules/shared/mail/send-mail";
|
||||
import { welcomeMail } from "@/modules/shared/mail/templates";
|
||||
import * as z from "zod";
|
||||
|
||||
|
||||
|
|
@ -13,7 +16,7 @@ const CreateClientSchema = z.object({
|
|||
|
||||
export type CreateClientState =
|
||||
| { error: string }
|
||||
| { success: true; email: string; password: string }
|
||||
| { success: true; email: string; password: string; welcomeMailSent: boolean }
|
||||
| undefined;
|
||||
|
||||
export async function createClient(
|
||||
|
|
@ -41,7 +44,7 @@ export async function createClient(
|
|||
const password = generatePassword();
|
||||
|
||||
const supabase = createAdminClient();
|
||||
const { error } = await supabase.auth.admin.createUser({
|
||||
const { data, error } = await supabase.auth.admin.createUser({
|
||||
email,
|
||||
password,
|
||||
email_confirm: true,
|
||||
|
|
@ -52,5 +55,13 @@ export async function createClient(
|
|||
return { error: error.code === "email_exists" ? "Diese Email ist bereits vergeben." : "Client konnte nicht angelegt werden." }
|
||||
}
|
||||
|
||||
return { success: true, email, password }
|
||||
const mail = welcomeMail({ name, email, appUrl: await getAppUrl() });
|
||||
const sent = await sendMail({
|
||||
to: email,
|
||||
...mail,
|
||||
type: "welcome",
|
||||
idempotencyKey: `welcome-${data.user.id}`,
|
||||
});
|
||||
|
||||
return { success: true, email, password, welcomeMailSent: sent.ok }
|
||||
}
|
||||
|
|
@ -25,6 +25,11 @@ function AddClientDialogContent({ onDone }: { onDone: () => void }) {
|
|||
<FieldGroup>
|
||||
<CopyField label="Email" value={state.email} />
|
||||
<CopyField label="Passwort" value={state.password} />
|
||||
{state.welcomeMailSent ? (
|
||||
<p className="text-small text-muted-foreground">Willkommensmail an {state.email} wurde gesendet.</p>
|
||||
) : (
|
||||
<p className="text-small text-destructive">Die Willkommensmail konnte nicht gesendet werden.</p>
|
||||
)}
|
||||
</FieldGroup>
|
||||
<DialogFooter className="mt-6">
|
||||
<Button type="button" onClick={onDone}>Fertig</Button>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue