mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-12-08 10:22:31 -05:00
fix: conditional imports
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
'use client';
|
||||
|
||||
import dynamic from 'next/dynamic';
|
||||
import type { Session } from 'next-auth';
|
||||
import { SessionProvider } from 'next-auth/react';
|
||||
import { MiniAppProvider } from '@neynar/react';
|
||||
import { SafeFarcasterSolanaProvider } from '~/components/providers/SafeFarcasterSolanaProvider';
|
||||
import { ANALYTICS_ENABLED } from '~/lib/constants';
|
||||
import { AuthKitProvider } from '@farcaster/auth-kit';
|
||||
|
||||
const WagmiProvider = dynamic(
|
||||
() => import('~/components/providers/WagmiProvider'),
|
||||
@@ -15,12 +12,14 @@ const WagmiProvider = dynamic(
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
export function Providers({
|
||||
session,
|
||||
children,
|
||||
shouldUseSession = false,
|
||||
}: {
|
||||
session: Session | null;
|
||||
session: any | null;
|
||||
children: React.ReactNode;
|
||||
shouldUseSession?: boolean;
|
||||
}) {
|
||||
@@ -29,19 +28,41 @@ export function Providers({
|
||||
|
||||
// Only wrap with SessionProvider if next auth is used
|
||||
if (shouldUseSession) {
|
||||
// Dynamic import for auth components - will work if modules exist, fallback if not
|
||||
const AuthWrapper = dynamic(
|
||||
() => {
|
||||
return Promise.resolve().then(() => {
|
||||
// Use eval to avoid build-time module resolution
|
||||
try {
|
||||
// @ts-ignore - These modules may not exist in all template variants
|
||||
const nextAuth = eval('require("next-auth/react")');
|
||||
const authKit = eval('require("@farcaster/auth-kit")');
|
||||
|
||||
return ({ children }: { children: React.ReactNode }) => (
|
||||
<nextAuth.SessionProvider session={session}>
|
||||
<authKit.AuthKitProvider config={{}}>{children}</authKit.AuthKitProvider>
|
||||
</nextAuth.SessionProvider>
|
||||
);
|
||||
} catch (error) {
|
||||
// Fallback component when auth modules aren't available
|
||||
return ({ children }: { children: React.ReactNode }) => <>{children}</>;
|
||||
}
|
||||
});
|
||||
},
|
||||
{ ssr: false }
|
||||
);
|
||||
|
||||
return (
|
||||
<SessionProvider session={session}>
|
||||
<WagmiProvider>
|
||||
<MiniAppProvider
|
||||
analyticsEnabled={ANALYTICS_ENABLED}
|
||||
backButtonEnabled={true}
|
||||
>
|
||||
<SafeFarcasterSolanaProvider endpoint={solanaEndpoint}>
|
||||
<AuthKitProvider config={{}}>{children}</AuthKitProvider>
|
||||
</SafeFarcasterSolanaProvider>
|
||||
</MiniAppProvider>
|
||||
</WagmiProvider>
|
||||
</SessionProvider>
|
||||
<WagmiProvider>
|
||||
<MiniAppProvider
|
||||
analyticsEnabled={ANALYTICS_ENABLED}
|
||||
backButtonEnabled={true}
|
||||
>
|
||||
<SafeFarcasterSolanaProvider endpoint={solanaEndpoint}>
|
||||
<AuthWrapper>{children}</AuthWrapper>
|
||||
</SafeFarcasterSolanaProvider>
|
||||
</MiniAppProvider>
|
||||
</WagmiProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,7 +74,7 @@ export function Providers({
|
||||
backButtonEnabled={true}
|
||||
>
|
||||
<SafeFarcasterSolanaProvider endpoint={solanaEndpoint}>
|
||||
<AuthKitProvider config={{}}>{children}</AuthKitProvider>
|
||||
{children}
|
||||
</SafeFarcasterSolanaProvider>
|
||||
</MiniAppProvider>
|
||||
</WagmiProvider>
|
||||
|
||||
Reference in New Issue
Block a user