feat: implement runtime authentication handling

- Added a new proxy function to manage runtime authentication types and set cookies accordingly.
- Introduced runtime authentication configuration to dynamically adjust UI based on the selected auth type.
- Updated global styles to hide specific authentication buttons based on the current auth type.
- Refactored sign-in button and hero section components to utilize the new runtime authentication logic.
- Created a new utility file for runtime authentication configuration and initialization script.
This commit is contained in:
Anish Sarkar 2026-06-19 03:56:26 +05:30
parent 03e57bdf7e
commit b54eff648e
6 changed files with 130 additions and 40 deletions

View file

@ -58,6 +58,11 @@
--highlight: oklch(0.852 0.199 91.936);
}
html[data-surfsense-auth-type="GOOGLE"] .runtime-auth-local,
html[data-surfsense-auth-type="LOCAL"] .runtime-auth-google {
display: none;
}
.dark {
--background: oklch(0.145 0 0);
--foreground: oklch(0.985 0 0);

View file

@ -2,6 +2,7 @@ import type { Metadata, Viewport } from "next";
import "./globals.css";
import { RootProvider } from "fumadocs-ui/provider/next";
import { Roboto } from "next/font/google";
import Script from "next/script";
import { AnnouncementToastProvider } from "@/components/announcements/AnnouncementToastProvider";
import { DesktopUpdateToast } from "@/components/desktop/desktop-update-toast";
import { GlobalLoadingProvider } from "@/components/providers/GlobalLoadingProvider";
@ -16,8 +17,13 @@ import {
import { ThemeProvider } from "@/components/theme/theme-provider";
import { Toaster } from "@/components/ui/sonner";
import { LocaleProvider } from "@/contexts/LocaleContext";
import { BUILD_TIME_AUTH_TYPE } from "@/lib/env-config";
import { PlatformProvider } from "@/contexts/platform-context";
import { ReactQueryClientProvider } from "@/lib/query-client/query-client.provider";
import {
getRuntimeAuthInitScript,
resolveRuntimeAuthUiMode,
} from "@/lib/runtime-auth-config";
import { cn } from "@/lib/utils";
const roboto = Roboto({
@ -131,8 +137,15 @@ export default function RootLayout({
// Language can be switched dynamically through LanguageSwitcher component
// Locale state is managed by LocaleContext and persisted in localStorage
return (
<html lang="en" suppressHydrationWarning>
<html
lang="en"
data-surfsense-auth-type={resolveRuntimeAuthUiMode(BUILD_TIME_AUTH_TYPE)}
suppressHydrationWarning
>
<head>
<Script id="surfsense-runtime-auth-init" strategy="beforeInteractive">
{getRuntimeAuthInitScript(BUILD_TIME_AUTH_TYPE)}
</Script>
<link rel="preconnect" href="https://api.github.com" />
<OrganizationJsonLd />
<WebSiteJsonLd />