Skip to content

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

Update shadcn-admin-kit for auth callback handling.

Matthieu Hochlandere56a7f0a343f
diff --git a/src/components/admin/admin.tsx b/src/components/admin/admin.tsx
index a856b413..ffcc3294 100644
--- a/src/components/admin/admin.tsx
+++ b/src/components/admin/admin.tsx
@@ -11,6 +11,7 @@ import { Layout } from "@/components/admin/layout";
import { LoginPage } from "@/components/admin/login-page";
import { Ready } from "@/components/admin/ready";
import { ThemeProvider } from "@/components/admin/theme-provider";
+import { AuthCallback } from "@/components/admin/authentication";
const defaultStore = localStorageStore();
@@ -24,6 +25,7 @@ const AdminUI = (props: CoreAdminUIProps) => (
layout={Layout}
loginPage={LoginPage}
ready={Ready}
+ authCallbackPage={AuthCallback}
{...props}
/>
</ThemeProvider>
@@ -32,7 +34,7 @@ const AdminUI = (props: CoreAdminUIProps) => (
export const Admin = (props: CoreAdminProps) => {
const {
accessDenied,
- authCallbackPage,
+ authCallbackPage = AuthCallback,
authenticationError,
authProvider,
basename,
diff --git a/src/components/admin/authentication.tsx b/src/components/admin/authentication.tsx
new file mode 100644
index 00000000..b928a94f
--- /dev/null
+++ b/src/components/admin/authentication.tsx
@@ -0,0 +1,67 @@
+import { useHandleAuthCallback, useTranslate } from "ra-core";
+import { cn } from "@/lib/utils";
+import { Loading } from "@/components/admin/loading";
+import { Button } from "@/components/ui/button";
+import { LockIcon } from "lucide-react";
+import { Link } from "react-router";
+
+/**
+ * A standalone page to be used in a route called by external authentication services (e.g. OAuth)
+ * after the user has been authenticated.
+ *
+ * Copy and adapt this component to implement your own login logic
+ * (e.g. to show a different waiting screen, start onboarding procedures, etc.).
+ *
+ * @example
+ * import MyAuthCallbackPage from './MyAuthCallbackPage';
+ * const App = () => (
+ * <Admin authCallbackPage={MyAuthCallbackPage} authProvider={authProvider}>
+ * ...
+ * </Admin>
+ * );
+ */
+export const AuthCallback = () => {
+ const { error } = useHandleAuthCallback();
+ if (error) {
+ return (
+ <AuthError
+ message={(error as Error) ? (error as Error).message : undefined}
+ />
+ );
+ }
+ return <Loading />;
+};
+
+export interface AuthErrorProps {
+ className?: string;
+ title?: string;
+ message?: string;
+}
+
+export const AuthError = (props: AuthErrorProps) => {
+ const {
+ className,
+ title = "ra.page.error",
+ message = "ra.message.auth_error",
+ ...rest
+ } = props;
+
+ const translate = useTranslate();
+ return (
+ <div
+ className={cn(
+ "flex flex-col justify-center items-center h-full",
+ className,
+ )}
+ {...rest}
+ >
+ <h1>{translate(title, { _: title })}</h1>
+ <div>{translate(message, { _: message })}</div>
+ <Button asChild>
+ <Link to="/login">
+ <LockIcon /> {translate("ra.auth.sign_in", { _: "Sign in" })}
+ </Link>
+ </Button>
+ </div>
+ );
+};