A full-featured CRM built with React, shadcn/ui, and Supabase.
Add oauth consent page
fzaninottod468e94b8a9f
diff --git a/package-lock.json b/package-lock.jsonindex 5a429496..1b45a9b2 100644--- a/package-lock.json+++ b/package-lock.json@@ -3843,77 +3843,83 @@"peer": true},"node_modules/@supabase/auth-js": {- "version": "2.71.1",- "resolved": "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.71.1.tgz",- "integrity": "sha512-mMIQHBRc+SKpZFRB2qtupuzulaUhFYupNyxqDj5Jp/LyPvcWvjaJzZzObv6URtL/O6lPxkanASnotGtNpS3H2Q==",+ "version": "2.89.0",+ "resolved": "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.89.0.tgz",+ "integrity": "sha512-wiWZdz8WMad8LQdJMWYDZ2SJtZP5MwMqzQq3ehtW2ngiI3UTgbKiFrvMUUS3KADiVlk4LiGfODB2mrYx7w2f8w==","license": "MIT","dependencies": {- "@supabase/node-fetch": "^2.6.14"+ "tslib": "2.8.1"+ },+ "engines": {+ "node": ">=20.0.0"}},"node_modules/@supabase/functions-js": {- "version": "2.4.5",- "resolved": "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.4.5.tgz",- "integrity": "sha512-v5GSqb9zbosquTo6gBwIiq7W9eQ7rE5QazsK/ezNiQXdCbY+bH8D9qEaBIkhVvX4ZRW5rP03gEfw5yw9tiq4EQ==",+ "version": "2.89.0",+ "resolved": "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.89.0.tgz",+ "integrity": "sha512-XEueaC5gMe5NufNYfBh9kPwJlP5M2f+Ogr8rvhmRDAZNHgY6mI35RCkYDijd92pMcNM7g8pUUJov93UGUnqfyw==","license": "MIT","dependencies": {- "@supabase/node-fetch": "^2.6.14"- }- },- "node_modules/@supabase/node-fetch": {- "version": "2.6.15",- "resolved": "https://registry.npmjs.org/@supabase/node-fetch/-/node-fetch-2.6.15.tgz",- "integrity": "sha512-1ibVeYUacxWYi9i0cf5efil6adJ9WRyZBLivgjs+AUpewx1F3xPi7gLgaASI2SmIQxPoCEjAsLAzKPgMJVgOUQ==",- "license": "MIT",- "dependencies": {- "whatwg-url": "^5.0.0"+ "tslib": "2.8.1"},"engines": {- "node": "4.x || >=6.0.0"+ "node": ">=20.0.0"}},"node_modules/@supabase/postgrest-js": {- "version": "1.21.3",- "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-1.21.3.tgz",- "integrity": "sha512-rg3DmmZQKEVCreXq6Am29hMVe1CzemXyIWVYyyua69y6XubfP+DzGfLxME/1uvdgwqdoaPbtjBDpEBhqxq1ZwA==",+ "version": "2.89.0",+ "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-2.89.0.tgz",+ "integrity": "sha512-/b0fKrxV9i7RNOEXMno/I1862RsYhuUo+Q6m6z3ar1f4ulTMXnDfv0y4YYxK2POcgrOXQOgKYQx1eArybyNvtg==","license": "MIT","dependencies": {- "@supabase/node-fetch": "^2.6.14"+ "tslib": "2.8.1"+ },+ "engines": {+ "node": ">=20.0.0"}},"node_modules/@supabase/realtime-js": {- "version": "2.15.4",- "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.15.4.tgz",- "integrity": "sha512-e/FYIWjvQJHOCNACWehnKvg26zosju3694k0NMUNb+JGLdvHJzEa29ZVVLmawd2kvx4hdbv8mxSqfttRnH3+DA==",+ "version": "2.89.0",+ "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.89.0.tgz",+ "integrity": "sha512-aMOvfDb2a52u6PX6jrrjvACHXGV3zsOlWRzZsTIOAJa0hOVvRp01AwC1+nLTGUzxzezejrYeCX+KnnM1xHdl+w==","license": "MIT","dependencies": {- "@supabase/node-fetch": "^2.6.13","@types/phoenix": "^1.6.6","@types/ws": "^8.18.1",+ "tslib": "2.8.1","ws": "^8.18.2"+ },+ "engines": {+ "node": ">=20.0.0"}},"node_modules/@supabase/storage-js": {- "version": "2.11.0",- "resolved": "https://registry.npmjs.org/@supabase/storage-js/-/storage-js-2.11.0.tgz",- "integrity": "sha512-Y+kx/wDgd4oasAgoAq0bsbQojwQ+ejIif8uczZ9qufRHWFLMU5cODT+ApHsSrDufqUcVKt+eyxtOXSkeh2v9ww==",+ "version": "2.89.0",+ "resolved": "https://registry.npmjs.org/@supabase/storage-js/-/storage-js-2.89.0.tgz",+ "integrity": "sha512-6zKcXofk/M/4Eato7iqpRh+B+vnxeiTumCIP+Tz26xEqIiywzD9JxHq+udRrDuv6hXE+pmetvJd8n5wcf4MFRQ==","license": "MIT","dependencies": {- "@supabase/node-fetch": "^2.6.14"+ "iceberg-js": "^0.8.1",+ "tslib": "2.8.1"+ },+ "engines": {+ "node": ">=20.0.0"}},"node_modules/@supabase/supabase-js": {- "version": "2.56.1",- "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.56.1.tgz",- "integrity": "sha512-cb/kS0d6G/qbcmUFItkqVrQbxQHWXzfRZuoiSDv/QiU6RbGNTn73XjjvmbBCZ4MMHs+5teihjhpEVluqbXISEg==",+ "version": "2.89.0",+ "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.89.0.tgz",+ "integrity": "sha512-KlaRwSfFA0fD73PYVMHj5/iXFtQGCcX7PSx0FdQwYEEw9b2wqM7GxadY+5YwcmuEhalmjFB/YvqaoNVF+sWUlg==","license": "MIT","dependencies": {- "@supabase/auth-js": "2.71.1",- "@supabase/functions-js": "2.4.5",- "@supabase/node-fetch": "2.6.15",- "@supabase/postgrest-js": "1.21.3",- "@supabase/realtime-js": "2.15.4",- "@supabase/storage-js": "^2.10.4"+ "@supabase/auth-js": "2.89.0",+ "@supabase/functions-js": "2.89.0",+ "@supabase/postgrest-js": "2.89.0",+ "@supabase/realtime-js": "2.89.0",+ "@supabase/storage-js": "2.89.0"+ },+ "engines": {+ "node": ">=20.0.0"}},"node_modules/@swc/counter": {@@ -7546,6 +7552,15 @@"url": "https://github.com/sponsors/typicode"}},+ "node_modules/iceberg-js": {+ "version": "0.8.1",+ "resolved": "https://registry.npmjs.org/iceberg-js/-/iceberg-js-0.8.1.tgz",+ "integrity": "sha512-1dhVQZXhcHje7798IVM+xoo/1ZdVfzOMIc8/rgVSijRK38EDqOJoGula9N/8ZI5RD8QTxNQtK/Gozpr+qUqRRA==",+ "license": "MIT",+ "engines": {+ "node": ">=20.0.0"+ }+ },"node_modules/iconv-lite": {"version": "0.6.3","resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",@@ -10953,12 +10968,6 @@"node": ">=16"}},- "node_modules/tr46": {- "version": "0.0.3",- "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",- "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",- "license": "MIT"- },"node_modules/trim-repeated": {"version": "1.0.0","resolved": "https://registry.npmjs.org/trim-repeated/-/trim-repeated-1.0.0.tgz",@@ -11539,22 +11548,6 @@"node": ">= 8"}},- "node_modules/webidl-conversions": {- "version": "3.0.1",- "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",- "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",- "license": "BSD-2-Clause"- },- "node_modules/whatwg-url": {- "version": "5.0.0",- "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",- "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",- "license": "MIT",- "dependencies": {- "tr46": "~0.0.3",- "webidl-conversions": "^3.0.0"- }- },"node_modules/which": {"version": "2.0.2","resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",diff --git a/src/components/atomic-crm/providers/fakerest/authProvider.ts b/src/components/atomic-crm/providers/fakerest/authProvider.tsindex 6fdd6cec..6e49406a 100644--- a/src/components/atomic-crm/providers/fakerest/authProvider.ts+++ b/src/components/atomic-crm/providers/fakerest/authProvider.ts@@ -71,4 +71,13 @@ export const authProvider: AuthProvider = {avatar: user?.avatar?.src,});},+ async getAuthorizationDetails() {+ throw new Error("Method not implemented.");+ },+ async approveAuthorization() {+ throw new Error("Method not implemented.");+ },+ async denyAuthorization() {+ throw new Error("Method not implemented.");+ },};diff --git a/src/components/atomic-crm/providers/supabase/authProvider.ts b/src/components/atomic-crm/providers/supabase/authProvider.tsindex b981161e..f37d117f 100644--- a/src/components/atomic-crm/providers/supabase/authProvider.ts+++ b/src/components/atomic-crm/providers/supabase/authProvider.ts@@ -91,6 +91,15 @@ export const authProvider: AuthProvider = {const role = sale.administrator ? "admin" : "user";return canAccess(role, params);},+ getAuthorizationDetails(authorizationId: string) {+ return supabase.auth.oauth.getAuthorizationDetails(authorizationId);+ },+ approveAuthorization(authorizationId: string) {+ return supabase.auth.oauth.approveAuthorization(authorizationId);+ },+ denyAuthorization(authorizationId: string) {+ return supabase.auth.oauth.denyAuthorization(authorizationId);+ },};let cachedSale: any;diff --git a/src/components/atomic-crm/root/CRM.tsx b/src/components/atomic-crm/root/CRM.tsxindex 6a87ee16..ed6076a2 100644--- a/src/components/atomic-crm/root/CRM.tsx+++ b/src/components/atomic-crm/root/CRM.tsx@@ -10,6 +10,7 @@ import { Route } from "react-router";import { Admin } from "@/components/admin/admin";import { ForgotPasswordPage } from "@/components/supabase/forgot-password-page";import { SetPasswordPage } from "@/components/supabase/set-password-page";+import { OAuthConsentPage } from "@/components/supabase/oauth-consent-page";import companies from "../companies";import contacts from "../contacts";@@ -148,6 +149,7 @@ export const CRM = ({path={ForgotPasswordPage.path}element={<ForgotPasswordPage />}/>+ <Route path={OAuthConsentPage.path} element={<OAuthConsentPage />} /></CustomRoutes><CustomRoutes>diff --git a/src/components/supabase/oauth-consent-page.tsx b/src/components/supabase/oauth-consent-page.tsxnew file mode 100644index 00000000..dde70421--- /dev/null+++ b/src/components/supabase/oauth-consent-page.tsx@@ -0,0 +1,162 @@+// src/pages/OAuthConsent.tsx+import { useEffect, useState } from "react";+import { useNavigate, useSearchParams } from "react-router-dom";+import { useAuthProvider } from "ra-core";++/**+ * Authorization UI for OAuth Consent Page+ *+ * When third-party apps initiate OAuth, users will be redirected to this page+ * to approve or deny the authorization request.+ *+ * Anonymous users will be redirected to the login page first.+ *+ * Inspired from https://supabase.com/docs/guides/auth/oauth-server/getting-started?queryGroups=oauth-setup&oauth-setup=dashboard#example-authorization-ui+ */+export function OAuthConsentPage() {+ const navigate = useNavigate();+ const [searchParams] = useSearchParams();+ const authorizationId = searchParams.get("authorization_id");+ const authProvider = useAuthProvider();++ const [authDetails, setAuthDetails] =+ useState<OAuthAuthorizationDetails | null>(null);+ const [loading, setLoading] = useState(true);+ const [error, setError] = useState<string | null>(null);++ useEffect(() => {+ async function loadAuthDetails() {+ if (!authorizationId) {+ setError("Missing authorization_id");+ setLoading(false);+ return;+ }+ if (!authProvider) {+ setError("Auth provider not available");+ setLoading(false);+ return;+ }++ // Check if user is authenticated+ try {+ await authProvider.checkAuth({});+ } catch {+ navigate(+ `/login?redirect=/oauth/consent?authorization_id=${authorizationId}`,+ );+ return;+ }++ // Get authorization details using the authorization_id+ const { data, error } =+ await authProvider.getAuthorizationDetails(authorizationId);++ if (error) {+ setError(error.message);+ } else {+ setAuthDetails(data as OAuthAuthorizationDetails);+ }++ setLoading(false);+ }++ loadAuthDetails();+ }, [authProvider, authorizationId, navigate]);++ async function handleApprove() {+ if (!authorizationId || !authProvider) return;++ const { data, error } =+ await authProvider.approveAuthorization(authorizationId);++ if (error) {+ setError(error.message);+ } else {+ // Redirect to client app+ window.location.href = data.redirect_to;+ }+ }++ async function handleDeny() {+ if (!authorizationId || !authProvider) return;++ const { data, error } =+ await authProvider.denyAuthorization(authorizationId);++ if (error) {+ setError(error.message);+ } else {+ // Redirect to client app with error+ window.location.href = data.redirect_to;+ }+ }++ if (loading) return <div>Loading...</div>;+ if (error) return <div>Error: {error}</div>;+ if (!authDetails) return <div>No authorization request found</div>;++ return (+ <div>+ <h1>Authorize {authDetails.client.name}</h1>+ <p>This application wants to access your account.</p>++ <div>+ <p>+ <strong>Client:</strong> {authDetails.client.name}+ </p>+ <p>+ <strong>Redirect URI:</strong> {authDetails.redirect_url}+ </p>+ {authDetails.scope && authDetails.scope.length > 0 && (+ <div>+ <strong>Requested permissions:</strong>+ <ul>+ {authDetails.scope.split(" ").map((scopeItem) => (+ <li key={scopeItem}>{scopeItem}</li>+ ))}+ </ul>+ </div>+ )}+ </div>++ <div>+ <button onClick={handleApprove}>Approve</button>+ <button onClick={handleDeny}>Deny</button>+ </div>+ </div>+ );+}++OAuthConsentPage.path = "/oauth/consent";++/**+ * copied from @supabase/auth-js/src/lib/types.ts+ * to avoid adding a hard import to a Supabase package+ * because this page can also be used with FakeRest+ */+type OAuthAuthorizationDetails = {+ /** The authorization ID */+ authorization_id: string;+ /** Redirect URL - present if user already consented (can be used to trigger immediate redirect) */+ redirect_url?: string;+ /** User object associated with the authorization */+ /** OAuth client requesting authorization */+ client: {+ /** Unique identifier for the OAuth client (UUID) */+ id: string;+ /** Human-readable name of the OAuth client */+ name: string;+ /** URI of the OAuth client's website */+ uri: string;+ /** URI of the OAuth client's logo */+ logo_uri: string;+ };+ user: {+ /** User ID (UUID) */+ id: string;+ /** User email */+ email: string;+ };+ /** Space-separated list of requested scopes */+ scope: string;+};