'use client'; import React, { useState, useEffect } from "react"; import { env } from "@/env.mjs"; interface AuthSecurityNoticeProps { closable?: boolean; } const AUTH_SECURITY_NOTICE_COOKIE = "auth-security-notice-dismissed"; const getSecurityNoticeDismissed = (): boolean => { if (typeof document === "undefined") return false; const cookies = document.cookie.split(';').map(cookie => cookie.trim()); const targetCookie = cookies.find(cookie => cookie.startsWith(`${AUTH_SECURITY_NOTICE_COOKIE}=`)); if (!targetCookie) return false; try { const cookieValue = targetCookie.substring(`${AUTH_SECURITY_NOTICE_COOKIE}=`.length); return JSON.parse(decodeURIComponent(cookieValue)); } catch (error) { console.warn('Failed to parse security notice cookie:', error); return false; } }; const setSecurityNoticeDismissed = (dismissed: boolean) => { if (typeof document === "undefined") return; try { const expires = new Date(); expires.setFullYear(expires.getFullYear() + 1); const cookieValue = encodeURIComponent(JSON.stringify(dismissed)); document.cookie = `${AUTH_SECURITY_NOTICE_COOKIE}=${cookieValue}; expires=${expires.toUTCString()}; path=/; SameSite=Lax`; } catch (error) { console.warn('Failed to set security notice cookie:', error); } }; export const AuthSecurityNotice = ({ closable = false }: AuthSecurityNoticeProps) => { const [isDismissed, setIsDismissed] = useState(false); const [hasMounted, setHasMounted] = useState(false); // Only check cookie after component mounts to avoid hydration error useEffect(() => { setHasMounted(true); if (closable) { setIsDismissed(getSecurityNoticeDismissed()); } }, [closable]); const handleDismiss = () => { setIsDismissed(true); setSecurityNoticeDismissed(true); }; // Don't render if dismissed when closable, or if closable but not yet mounted if (closable && (!hasMounted || isDismissed)) { return null; } // Only render for self-hosted deployments if (env.NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT !== undefined) { return null; } return (
Security Notice: Authentication data is managed by your deployment and is encrypted at rest. Zero data leaves your deployment.{' '} Learn more