metatron-open-seo/src/client/components/UnauthenticatedErrorCard.tsx
Ben Senescu bfc6a97466
refactor project layouts around route boundaries (#45)
* refactor: align app layouts with route boundaries

* fix: honor auth redirect search in auth layout
2026-03-24 17:50:35 -04:00

52 lines
1.4 KiB
TypeScript

import { useEffect } from "react";
import { getSignInHref, getSignInHrefForLocation } from "@/lib/auth-redirect";
import { isHostedClientAuthMode } from "@/lib/auth-mode";
type UnauthenticatedErrorCardProps = {
message: string;
onRetry?: () => void;
};
export function UnauthenticatedErrorCard({
message,
onRetry,
}: UnauthenticatedErrorCardProps) {
const isHostedMode = isHostedClientAuthMode();
const signInHref =
typeof window === "undefined"
? getSignInHref("/")
: getSignInHrefForLocation(window.location);
useEffect(() => {
if (typeof window === "undefined" || !isHostedMode) {
return;
}
window.location.replace(signInHref);
}, [isHostedMode, signInHref]);
if (isHostedMode) {
return null;
}
return (
<div className="card w-full max-w-md bg-base-100 border border-base-300 shadow-xl">
<div className="card-body gap-4">
<h2 className="card-title">Authentication required</h2>
<p className="text-sm text-base-content/70">{message}</p>
<p className="text-sm text-base-content/70">
This deployment uses external authentication. Refresh your access
session, then try again.
</p>
{onRetry ? (
<div className="card-actions justify-end">
<button className="btn btn-primary btn-sm" onClick={onRetry}>
Try Again
</button>
</div>
) : null}
</div>
</div>
);
}