Skip to content

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

Feat(auth): Handle redirection from supabase with HashRouter

Anthony Rimet2e20d7b21401
diff --git a/package-lock.json b/package-lock.json
index 2d882c6d..3eb1fa6b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -23,7 +23,7 @@
"papaparse": "^5.4.1",
"prop-types": "^15.8.1",
"ra-data-fakerest": "^5.1.1",
- "ra-supabase": "^3.0.0",
+ "ra-supabase": "^3.0.1",
"react": "^18.2.0",
"react-admin": "^5.1.0",
"react-cropper": "^2.3.3",
@@ -10570,19 +10570,19 @@
}
},
"node_modules/ra-supabase": {
- "version": "3.0.0",
- "resolved": "https://registry.npmjs.org/ra-supabase/-/ra-supabase-3.0.0.tgz",
- "integrity": "sha512-vBVPyPkPhlfuAJp5CnQseNioBcpqGjfz9MOuOekXsRRXA+5dv8nJfp9XnX7wytGU4oax+gRNqlXJMZJEtZDJXQ==",
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/ra-supabase/-/ra-supabase-3.1.0.tgz",
+ "integrity": "sha512-T+OtQ4FTYcJqWUdgZ5rcLamHbU2Ae0BqMEuBLry9sXPUFOtsh26+zShFRe6mtkbJA2ydjfiYW01/n5SQrWP2eg==",
"dependencies": {
- "ra-supabase-core": "^3.0.0",
- "ra-supabase-language-english": "^3.0.0",
- "ra-supabase-ui-materialui": "^3.0.0"
+ "ra-supabase-core": "^3.1.0",
+ "ra-supabase-language-english": "^3.1.0",
+ "ra-supabase-ui-materialui": "^3.1.0"
}
},
"node_modules/ra-supabase-core": {
- "version": "3.0.0",
- "resolved": "https://registry.npmjs.org/ra-supabase-core/-/ra-supabase-core-3.0.0.tgz",
- "integrity": "sha512-V6OHsgOE7icqH6ZstwOjny55mxPeSh2mmAdsUnuiYORk6mWAq8g7d5ba8pZHhowXKiUK3G0Pw9VEqMVIZ55y2g==",
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/ra-supabase-core/-/ra-supabase-core-3.1.0.tgz",
+ "integrity": "sha512-KagSKm+fJLkQTtNc7OtejktXMIysv80ZgOzJAM5nz+xyHNVhFb2GEbW+AvYI3uXejay/cQL8WvfQkczl/NeZ7Q==",
"peerDependencies": {
"@raphiniert/ra-data-postgrest": "^2.3.0",
"@supabase/supabase-js": "^2.0.0",
@@ -10590,16 +10590,16 @@
}
},
"node_modules/ra-supabase-language-english": {
- "version": "3.0.0",
- "resolved": "https://registry.npmjs.org/ra-supabase-language-english/-/ra-supabase-language-english-3.0.0.tgz",
- "integrity": "sha512-V1VJrUnAZWTys1s7Qv7xJx55mxDrgui7E22NtNPe+ET+TROsLs7xtDZmsWcmMDTOpqnzuqyPS5x/zmJDJ7/uxw=="
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/ra-supabase-language-english/-/ra-supabase-language-english-3.1.0.tgz",
+ "integrity": "sha512-9/S8n6quJeJiOcFVLDZQNqXOMcGnlwmdZ+Xy4UFGcfdsGCuPr68CYxdG68WnP1jxyo7Hy7b/zvfr+Zu5rW8f+g=="
},
"node_modules/ra-supabase-ui-materialui": {
- "version": "3.0.0",
- "resolved": "https://registry.npmjs.org/ra-supabase-ui-materialui/-/ra-supabase-ui-materialui-3.0.0.tgz",
- "integrity": "sha512-BcZr4AeqCfSLpc+fUWaaKzw+F5xI3bp9nBmSuk+eoUW7c67uDqY0eSi7kO5HmiM6WoCnerfhrDrljAs4JKMavg==",
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/ra-supabase-ui-materialui/-/ra-supabase-ui-materialui-3.1.0.tgz",
+ "integrity": "sha512-F/6JfoBEwW4wAZ/0b8ccJ/EqjGR460+ermU1HuGxXXj5YCd9Gg6Oc+YDcKlSZ7F0bH16DI9Q8z08EXns6cvyQw==",
"dependencies": {
- "ra-supabase-core": "^3.0.0"
+ "ra-supabase-core": "^3.1.0"
},
"peerDependencies": {
"@mui/icons-material": "^5.0.0",
diff --git a/package.json b/package.json
index 0661a8ca..5880b07d 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,7 @@
"papaparse": "^5.4.1",
"prop-types": "^15.8.1",
"ra-data-fakerest": "^5.1.1",
- "ra-supabase": "^3.0.0",
+ "ra-supabase": "^3.0.1",
"react": "^18.2.0",
"react-admin": "^5.1.0",
"react-cropper": "^2.3.3",
diff --git a/public/auth-callback/index.html b/public/auth-callback.html
similarity index 97%
rename from public/auth-callback/index.html
rename to public/auth-callback.html
index ef7d2924..ab2d5f06 100644
--- a/public/auth-callback/index.html
+++ b/public/auth-callback.html
@@ -131,7 +131,7 @@
function interceptAuthCallback() {
const hash = window.location.hash;
const {access_token, refresh_token, type} = getUrlParams();
- window.location.href = `../?access_token=${access_token}&refresh_token=${refresh_token}&type=${type}#/auth-callback`;
+ window.location.href = `../#/auth-callback?access_token=${access_token}&refresh_token=${refresh_token}&type=${type}`;
}
// Call the function to intercept the auth callback
diff --git a/src/providers/supabase/authProvider.ts b/src/providers/supabase/authProvider.ts
index 2a264773..997365c6 100644
--- a/src/providers/supabase/authProvider.ts
+++ b/src/providers/supabase/authProvider.ts
@@ -56,30 +56,4 @@ export const authProvider: AuthProvider = {
return baseAuthProvider.checkAuth(params);
},
- handleCallback: async () => {
- const { access_token, refresh_token, type } = getUrlParams();
- // Users have reset their password or have just been invited and must set a new password
- if (type === 'recovery' || type === 'invite') {
- if (access_token && refresh_token) {
- return {
- redirectTo: `/set-password?access_token=${access_token}&refresh_token=${refresh_token}&type=${type}`,
- };
- }
-
- if (process.env.NODE_ENV === 'development') {
- console.error(
- 'Missing access_token or refresh_token for an invite or recovery'
- );
- }
- }
- },
-};
-
-const getUrlParams = () => {
- const urlSearchParams = new URLSearchParams(window.location.search);
- const access_token = urlSearchParams.get('access_token');
- const refresh_token = urlSearchParams.get('refresh_token');
- const type = urlSearchParams.get('type');
-
- return { access_token, refresh_token, type };
};
diff --git a/supabase/config.toml b/supabase/config.toml
index df13d88e..f061d998 100644
--- a/supabase/config.toml
+++ b/supabase/config.toml
@@ -71,7 +71,7 @@ enabled = true
# in emails.
site_url = "http://localhost:5173/"
# A list of *exact* URLs that auth providers are permitted to redirect to post authentication.
-additional_redirect_urls = ["https://localhost:5173/auth-callback/index.html"]
+additional_redirect_urls = ["https://localhost:5173/auth-callback.html"]
# 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.
diff --git a/supabase/templates/recovery.html b/supabase/templates/recovery.html
index e021e566..e0ec1037 100644
--- a/supabase/templates/recovery.html
+++ b/supabase/templates/recovery.html
@@ -61,7 +61,7 @@
<p>Hello,</p>
<p>To reset your password, follow the link below:</p>
<a
- href="{{ .ConfirmationURL }}auth-callback/index.html"
+ href="{{ .ConfirmationURL }}auth-callback.html"
class="button"
>Reset my password</a
>