Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Feat(auth): Create invite email

Anthony Rimetdb7f8dd1e758
diff --git a/src/sales/SalesCreate.tsx b/src/sales/SalesCreate.tsx
index b4d3c708..320efe0a 100644
--- a/src/sales/SalesCreate.tsx
+++ b/src/sales/SalesCreate.tsx
@@ -1,8 +1,6 @@
import { Card, Container, Typography } from '@mui/material';
import { useMutation } from '@tanstack/react-query';
import {
- PasswordInput,
- required,
SimpleForm,
useDataProvider,
useNotify,
@@ -39,13 +37,7 @@ export function SalesCreate() {
<Card>
<SimpleForm onSubmit={onSubmit as SubmitHandler<any>}>
<Typography variant="h6">Create sale person</Typography>
- <SalesInputs>
- <PasswordInput
- source="password"
- validate={required()}
- helperText={false}
- />
- </SalesInputs>
+ <SalesInputs />
</SimpleForm>
</Card>
</Container>
diff --git a/src/sales/SalesInputs.tsx b/src/sales/SalesInputs.tsx
index 0f6b70bb..c0440bf2 100644
--- a/src/sales/SalesInputs.tsx
+++ b/src/sales/SalesInputs.tsx
@@ -6,10 +6,9 @@ import {
useRecordContext,
} from 'react-admin';
import { Sale } from '../types';
-import { ReactNode } from 'react';
import { Stack } from '@mui/material';
-export function SalesInputs({ children }: { children?: ReactNode }) {
+export function SalesInputs() {
const { identity } = useGetIdentity();
const record = useRecordContext<Sale>();
return (
@@ -29,7 +28,6 @@ export function SalesInputs({ children }: { children?: ReactNode }) {
validate={required()}
helperText={false}
/>
- {children}
<BooleanInput
source="administrator"
readOnly={record?.id === identity?.id}
diff --git a/supabase/config.toml b/supabase/config.toml
index f061d998..e5fdc7f4 100644
--- a/supabase/config.toml
+++ b/supabase/config.toml
@@ -91,10 +91,9 @@ double_confirm_changes = true
# If enabled, users need to confirm their email address before signing in.
enable_confirmations = false
-# Uncomment to customize email template
-# [auth.email.template.invite]
-# subject = "You have been invited"
-# content_path = "./supabase/templates/invite.html"
+[auth.email.template.invite]
+subject = "You've been invited to use Atomic CRM"
+content_path = "./supabase/templates/invite.html"
[auth.email.template.recovery]
subject = "Reset Password"
diff --git a/supabase/functions/users/index.ts b/supabase/functions/users/index.ts
index 4f7ce8cb..34d3116b 100644
--- a/supabase/functions/users/index.ts
+++ b/supabase/functions/users/index.ts
@@ -35,10 +35,12 @@ async function inviteUser(req: Request) {
await supabaseAdmin.auth.admin.createUser({
email,
password,
- email_confirm: true,
user_metadata: { first_name, last_name },
});
+ const { data: emailData, error: emailError } =
+ await supabaseAdmin.auth.admin.inviteUserByEmail(email);
+
if (!data?.user || userError) {
console.error('Error inviting user:', userError);
return createErrorResponse(500, 'Internal Server Error');
diff --git a/supabase/templates/invite.html b/supabase/templates/invite.html
new file mode 100644
index 00000000..335126e8
--- /dev/null
+++ b/supabase/templates/invite.html
@@ -0,0 +1,90 @@
+<!doctype html>
+<html>
+ <head>
+ <style>
+ body {
+ font-family: Arial, sans-serif;
+ background-color: #f4f4f4;
+ margin: 0;
+ padding: 0;
+ }
+ .container {
+ width: 100%;
+ max-width: 600px;
+ margin: 0 auto;
+ background-color: #ffffff;
+ padding: 20px;
+ border-radius: 8px;
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
+ }
+ .header {
+ text-align: center;
+ padding: 10px 0;
+ }
+ .header h2 {
+ margin: 0;
+ color: #333333;
+ }
+ .content {
+ padding: 20px;
+ line-height: 1.6;
+ color: #555555;
+ }
+ .content p {
+ margin: 0 0 10px;
+ }
+ .button {
+ display: block;
+ width: 200px;
+ margin: 20px auto;
+ padding: 10px;
+ text-align: center;
+ background-color: #007bff;
+ color: #ffffff;
+ text-decoration: none;
+ border-radius: 5px;
+ }
+ .footer {
+ text-align: center;
+ padding: 10px 0;
+ font-size: 12px;
+ color: #777777;
+ }
+ </style>
+ </head>
+ <body>
+ <div class="container">
+ <div class="header">
+ <h2>Confirm your account</h2>
+ </div>
+ <div class="content">
+ <p>Welcome to Atomic CRM.</p>
+ <p>
+ You've been invited to join the (Name) organization. Confirm
+ your address below:
+ </p>
+ <a
+ href="{{ .ConfirmationURL }}auth-callback.html"
+ class="button"
+ >Confirm my account</a
+ >
+ <p>
+ <strong>Warning:</strong> If the password reset request did
+ not originate from you, please contact us immediately as
+ this may be a fraudulent attempt.
+ </p>
+ <p>See you soon!</p>
+ <p>The Atomic CRM team</p>
+ </div>
+ <div class="footer">
+ <p>
+ If the activation link doesn’t work,
+ <a
+ href="mailto:[email protected]"
+ >contact us</a
+ >.
+ </p>
+ </div>
+ </div>
+ </body>
+</html>