Skip to content

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

Feat(auth): Add reset-password for Sales

Anthony Rimet19f780aafccf
diff --git a/README.md b/README.md
index b528fcbd..2f045406 100644
--- a/README.md
+++ b/README.md
@@ -99,4 +99,32 @@ have to create the following secrets:
SUPABASE_ACCESS_TOKEN: Your personal access token, can be found at https://supabase.com/dashboard/account/tokens
SUPABASE_DB_PASSWORD: Your supabase database password
SUPABASE_PROJECT_ID: Your supabase project id
+```
+
+## Supabase
+
+### Password Reset When Forgotten
+If users forgot their password, they can request for a reset. Atomic CRM handle it for you. All the magic is done by the custom route `/forgot-password` and `/reset-password` that you can find in the `CRM` component.
+
+If you want to update default configuration:
+
+1. Go to your `config.toml` file
+2. In `[auth]` section set `site_url` to your application URL
+3. In `[auth]`, add the following URL in the `additional_redirect_urls = [{APPLICATION_URL}}/auth-callback"]`
+4. Add an `[auth.email.templace.recovery]` section with the following option
+```
+[auth.email.template.recovery]
+subject = "Reset Password"
+content_path = "./supabase/templates/recovery.html"
+```
+
+In Recovery email template set the `auth-callback` redirection
+
+```HTML
+<html>
+ <body>
+ <h2>Reset Password</h2>
+ <p><a href="{{ .ConfirmationURL }}/auth-callback">Reset your password</a></p>
+ </body>
+</html>
```
\ No newline at end of file
diff --git a/src/login/LoginForm.tsx b/src/login/LoginForm.tsx
index 44268c16..88a079ba 100644
--- a/src/login/LoginForm.tsx
+++ b/src/login/LoginForm.tsx
@@ -5,10 +5,13 @@ import {
CardActions,
CardContent,
CircularProgress,
+ Typography,
} from '@mui/material';
import { Form, useLogin, useNotify, useSafeSetState } from 'ra-core';
import { Login, TextInput } from 'react-admin';
import { SubmitHandler } from 'react-hook-form';
+import { Link } from 'react-router-dom';
+import { ForgotPasswordPage } from 'ra-supabase';
const PREFIX = 'RaLoginForm';
@@ -103,6 +106,13 @@ export const LoginForm = () => {
'Sign In'
)}
</Button>
+ <Typography
+ component={Link}
+ to={ForgotPasswordPage.path}
+ variant="caption"
+ >
+ Forgot your password?
+ </Typography>
</CardActions>
</StyledForm>
</Login>
diff --git a/src/root/CRM.tsx b/src/root/CRM.tsx
index ffb635bc..cfa5628b 100644
--- a/src/root/CRM.tsx
+++ b/src/root/CRM.tsx
@@ -37,6 +37,9 @@ import {
defaultTitle,
} from './defaultConfiguration';
+import { SetPasswordPage, ForgotPasswordPage } from 'ra-supabase';
+import { BrowserRouter } from 'react-router-dom';
+
// Define the interface for the CRM component props
type CRMProps = {
lightTheme?: RaThemeOptions;
@@ -126,39 +129,49 @@ export const CRM = ({
taskTypes={taskTypes}
title={title}
>
- <Admin
- dataProvider={dataProvider}
- authProvider={authProvider}
- store={localStorageStore(undefined, 'CRM')}
- layout={Layout}
- loginPage={LoginPage}
- dashboard={Dashboard}
- theme={lightTheme}
- darkTheme={darkTheme || null}
- >
- <CustomRoutes noLayout>
- <Route path={SignupPage.path} element={<SignupPage />} />
- </CustomRoutes>
- {permissions => (
- <>
- <CustomRoutes>
- <Route
- path={SettingsPage.path}
- element={<SettingsPage />}
- />
- </CustomRoutes>
- <Resource name="deals" {...deals} />
- <Resource name="contacts" {...contacts} />
- <Resource name="companies" {...companies} />
- <Resource name="contactNotes" />
- <Resource name="dealNotes" />
- <Resource name="tasks" list={ListGuesser} />
- {permissions === 'admin' ? (
- <Resource name="sales" {...sales} />
- ) : null}
- <Resource name="tags" list={ListGuesser} />
- </>
- )}
- </Admin>
+ <BrowserRouter>
+ <Admin
+ dataProvider={dataProvider}
+ authProvider={authProvider}
+ store={localStorageStore(undefined, 'CRM')}
+ layout={Layout}
+ loginPage={LoginPage}
+ dashboard={Dashboard}
+ theme={lightTheme}
+ darkTheme={darkTheme || null}
+ >
+ <CustomRoutes noLayout>
+ <Route path={SignupPage.path} element={<SignupPage />} />
+ <Route
+ path={SetPasswordPage.path}
+ element={<SetPasswordPage />}
+ />
+ <Route
+ path={ForgotPasswordPage.path}
+ element={<ForgotPasswordPage />}
+ />
+ </CustomRoutes>
+ {permissions => (
+ <>
+ <CustomRoutes>
+ <Route
+ path={SettingsPage.path}
+ element={<SettingsPage />}
+ />
+ </CustomRoutes>
+ <Resource name="deals" {...deals} />
+ <Resource name="contacts" {...contacts} />
+ <Resource name="companies" {...companies} />
+ <Resource name="contactNotes" />
+ <Resource name="dealNotes" />
+ <Resource name="tasks" list={ListGuesser} />
+ {permissions === 'admin' ? (
+ <Resource name="sales" {...sales} />
+ ) : null}
+ <Resource name="tags" list={ListGuesser} />
+ </>
+ )}
+ </Admin>
+ </BrowserRouter>
</ConfigurationProvider>
);
diff --git a/supabase/config.toml b/supabase/config.toml
index 4e1e101d..dce32d94 100644
--- a/supabase/config.toml
+++ b/supabase/config.toml
@@ -69,9 +69,9 @@ file_size_limit = "50MiB"
enabled = true
# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used
# in emails.
-site_url = "http://127.0.0.1:3000"
+site_url = "http://127.0.0.1:5173"
# A list of *exact* URLs that auth providers are permitted to redirect to post authentication.
-additional_redirect_urls = ["https://127.0.0.1:3000"]
+additional_redirect_urls = ["https://127.0.0.1:5173/auth-callback"]
# How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 (1 week).
jwt_expiry = 3600
# If disabled, the refresh token will never expire.
@@ -96,6 +96,10 @@ enable_confirmations = false
# subject = "You have been invited"
# content_path = "./supabase/templates/invite.html"
+[auth.email.template.recovery]
+subject = "Reset Password"
+content_path = "./supabase/templates/recovery.html"
+
[auth.sms]
# Allow/disallow new user signups via SMS to your project.
enable_signup = true
diff --git a/supabase/templates/recovery.html b/supabase/templates/recovery.html
new file mode 100644
index 00000000..611f8ce4
--- /dev/null
+++ b/supabase/templates/recovery.html
@@ -0,0 +1,85 @@
+<!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>Reset Password</h2>
+ </div>
+ <div class="content">
+ <p>Hello,</p>
+ <p>To reset your password, follow the link below:</p>
+ <a href="{{ .ConfirmationURL }}/auth-callback" class="button"
+ >Reset my password</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>Keep up the great work!</p>
+ <p>The Atomic CRM team</p>
+ </div>
+ <div class="footer">
+ <p>
+ If you need help, feel free to
+ <a
+ href="mailto:[email protected]"
+ >contact us</a
+ >.
+ </p>
+ </div>
+ </div>
+ </body>
+</html>