import { useCallback, useEffect, useState, type FormEvent } from 'react'; import { getSikshyaApi, SIKSHYA_ENDPOINTS } from '../api'; import { EmbeddableShell } from '../components/shared/EmbeddableShell'; import { GatedFeatureWorkspace } from '../components/GatedFeatureWorkspace'; import { ApiErrorPanel } from '../components/shared/ApiErrorPanel'; import { ListPanel } from '../components/shared/list/ListPanel'; import { ButtonPrimary } from '../components/shared/buttons'; import { TopRightToast, useTopRightToast } from '../components/shared/TopRightToast'; import { useAsyncData } from '../hooks/useAsyncData'; import { useAddonEnabled } from '../hooks/useAddons'; import { isFeatureEnabled, resolveGatedWorkspaceMode } from '../lib/licensing'; import type { SikshyaReactConfig } from '../types'; import { __ } from '../lib/i18n'; type Options = { google_client_id?: string; google_client_secret?: string; google_client_secret_set?: boolean; facebook_app_id?: string; facebook_app_secret?: string; facebook_app_secret_set?: boolean; show_login_notice?: boolean; show_wp_login_buttons?: boolean; show_on_course_page?: boolean; show_on_cart?: boolean; show_account_linking?: boolean; allow_social_registration?: boolean; link_matching_verified_email?: boolean; require_google_email_verified?: boolean; oauth_callback_url?: string; users_can_register?: boolean; }; type Resp = { ok?: boolean; options?: Options }; export function SocialLoginPage(props: { config: SikshyaReactConfig; title: string; embedded?: boolean }) { const { config, title, embedded } = props; const featureOk = isFeatureEnabled(config, 'social_login'); const addon = useAddonEnabled('social_login'); const mode = resolveGatedWorkspaceMode(featureOk, addon.enabled, addon.loading); const enabled = mode === 'full'; const [opts, setOpts] = useState({}); const [saving, setSaving] = useState(false); const toast = useTopRightToast(); const loader = useCallback(async () => { if (!enabled) return { ok: true, options: {} as Options }; return getSikshyaApi().get(SIKSHYA_ENDPOINTS.pro.socialLogin); }, [enabled]); const { loading, data, error, refetch } = useAsyncData(loader, [enabled]); useEffect(() => { if (data?.options) { setOpts({ ...data.options }); } }, [data]); const onSave = async (e: FormEvent) => { e.preventDefault(); setSaving(true); try { await getSikshyaApi().post(SIKSHYA_ENDPOINTS.pro.socialLogin, opts); toast.success(__('Saved', 'sikshya'), 'Social login settings saved.'); refetch(); } catch (err) { toast.error(__('Save failed', 'sikshya'), err instanceof Error ? err.message : 'Save failed'); } finally { setSaving(false); } }; return ( addon.enable()} addonError={addon.error} > {error ? refetch()} /> : null} {loading ? (

{__('Loading…', 'sikshya')}

) : (

{__('Redirect / callback URL', 'sikshya')}

Add this exact URL as the authorized redirect URI in your provider console.

{__('Google', 'sikshya')}

Create OAuth credentials in the Google Cloud Console and paste them here. Use the WordPress login URL as the authorized redirect URI.

{__('Facebook', 'sikshya')}

Create an app in Meta for Developers and paste the keys below.

Placement & behavior

Security & registration

{saving ? __('Saving…', 'sikshya') : __('Save settings', 'sikshya')}
)}
); }