"use client"; import { useState, useEffect } from "react"; interface SocialMedia { url: string; display: boolean; } interface Socials { facebook?: SocialMedia; instagram?: SocialMedia; twitter?: SocialMedia; linkedin?: SocialMedia; youtube?: SocialMedia; } interface OAuthProvider { enabled: boolean; clientId: string; clientSecret: string; } interface OAuthConfig { google?: OAuthProvider; github?: OAuthProvider; facebook?: OAuthProvider; discord?: OAuthProvider; } export default function AdminSetupPage() { const [config, setConfig] = useState({ googleAuth: { enabled: false, clientId: "", clientSecret: "", }, oauth: { google: { enabled: false, clientId: "", clientSecret: "" }, github: { enabled: false, clientId: "", clientSecret: "" }, facebook: { enabled: false, clientId: "", clientSecret: "" }, discord: { enabled: false, clientId: "", clientSecret: "" }, } as OAuthConfig, googleCalendar: { enabled: false, serviceAccountEmail: "", serviceAccountKey: "", calendarId: "", }, socials: {} as Socials, email: { smtp: { enabled: false, host: "", port: 587, username: "", password: "", from: "", }, }, pagination: { itemsPerPage: 10, }, }); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [message, setMessage] = useState(""); useEffect(() => { fetchConfig(); }, []); const fetchConfig = async () => { try { const response = await fetch("/api/admin/setup"); const data = await response.json(); if (data.ok) { // Ensure oauth object exists with all providers const fetchedConfig = data.data; if (!fetchedConfig.oauth) { fetchedConfig.oauth = { google: { enabled: false, clientId: "", clientSecret: "" }, github: { enabled: false, clientId: "", clientSecret: "" }, facebook: { enabled: false, clientId: "", clientSecret: "" }, discord: { enabled: false, clientId: "", clientSecret: "" }, }; } setConfig(fetchedConfig); } else { setMessage(`❌ Failed to load config: ${data.message}`); } } catch (error) { console.error("Error fetching config:", error); setMessage(`❌ Error loading configuration: ${error}`); } finally { setLoading(false); } }; const handleSave = async () => { setSaving(true); setMessage(""); try { const response = await fetch("/api/admin/setup", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(config), }); const data = await response.json(); if (data.ok) { setMessage("✅ Settings saved successfully!"); } else { setMessage(`❌ ${data.message}`); } } catch (error) { setMessage("❌ Failed to save settings"); } finally { setSaving(false); setTimeout(() => setMessage(""), 3000); } }; const updateSocial = (platform: keyof Socials, field: "url" | "display", value: string | boolean) => { setConfig({ ...config, socials: { ...config.socials, [platform]: { ...config.socials[platform], [field]: value, }, }, }); }; if (loading) { return (
Loading configuration...
); } return (
🛠️ Admin Settings

System Setup

Configure authentication, social media, and email settings

{/* Google OAuth Configuration */}
🔐

Google OAuth

Enable Google sign-in for users

setConfig({ ...config, googleAuth: { ...config.googleAuth, enabled: e.target.checked }, }) } className="w-5 h-5 text-primary border-gray-300 rounded focus:ring-primary" />
setConfig({ ...config, googleAuth: { ...config.googleAuth, clientId: e.target.value }, }) } />
setConfig({ ...config, googleAuth: { ...config.googleAuth, clientSecret: e.target.value }, }) } />
{/* BetterAuth OAuth Providers */}
🔑 OAuth Providers (BetterAuth)

Configure social OAuth providers for user authentication. Get credentials from each provider's developer console.

{/* Google OAuth */}
🔍

Google

setConfig({ ...config, oauth: { ...config.oauth, google: { ...(config.oauth.google || {}), enabled: e.target.checked } as OAuthProvider, }, }) } className="w-4 h-4 text-primary border-gray-300 rounded focus:ring-primary" />
setConfig({ ...config, oauth: { ...config.oauth, google: { ...(config.oauth.google || {}), clientId: e.target.value } as OAuthProvider, }, }) } /> setConfig({ ...config, oauth: { ...config.oauth, google: { ...(config.oauth.google || {}), clientSecret: e.target.value } as OAuthProvider, }, }) } />
{/* GitHub OAuth */}
🐙

GitHub

setConfig({ ...config, oauth: { ...config.oauth, github: { ...(config.oauth.github || {}), enabled: e.target.checked } as OAuthProvider, }, }) } className="w-4 h-4 text-primary border-gray-300 rounded focus:ring-primary" />
setConfig({ ...config, oauth: { ...config.oauth, github: { ...(config.oauth.github || {}), clientId: e.target.value } as OAuthProvider, }, }) } /> setConfig({ ...config, oauth: { ...config.oauth, github: { ...(config.oauth.github || {}), clientSecret: e.target.value } as OAuthProvider, }, }) } />
{/* Facebook OAuth */}
👍

Facebook

setConfig({ ...config, oauth: { ...config.oauth, facebook: { ...(config.oauth.facebook || {}), enabled: e.target.checked } as OAuthProvider, }, }) } className="w-4 h-4 text-primary border-gray-300 rounded focus:ring-primary" />
setConfig({ ...config, oauth: { ...config.oauth, facebook: { ...(config.oauth.facebook || {}), clientId: e.target.value } as OAuthProvider, }, }) } /> setConfig({ ...config, oauth: { ...config.oauth, facebook: { ...(config.oauth.facebook || {}), clientSecret: e.target.value } as OAuthProvider, }, }) } />
{/* Discord OAuth */}
💬

Discord

setConfig({ ...config, oauth: { ...config.oauth, discord: { ...(config.oauth.discord || {}), enabled: e.target.checked } as OAuthProvider, }, }) } className="w-4 h-4 text-primary border-gray-300 rounded focus:ring-primary" />
setConfig({ ...config, oauth: { ...config.oauth, discord: { ...(config.oauth.discord || {}), clientId: e.target.value } as OAuthProvider, }, }) } /> setConfig({ ...config, oauth: { ...config.oauth, discord: { ...(config.oauth.discord || {}), clientSecret: e.target.value } as OAuthProvider, }, }) } />
{/* Google Calendar Configuration */}
📅

Google Calendar

Enable calendar invites for webinar registrations

setConfig({ ...config, googleCalendar: { ...config.googleCalendar, enabled: e.target.checked }, }) } className="w-5 h-5 text-primary border-gray-300 rounded focus:ring-primary" />
setConfig({ ...config, googleCalendar: { ...config.googleCalendar, serviceAccountEmail: e.target.value }, }) } />

Create a service account in Google Cloud Console