mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-11-15 23:58:56 -05:00
fix: conditional imports
This commit is contained in:
parent
2edd1bd2ae
commit
d9c74f163b
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@neynar/create-farcaster-mini-app",
|
||||
"version": "1.7.8",
|
||||
"version": "1.7.9",
|
||||
"type": "module",
|
||||
"private": false,
|
||||
"access": "public",
|
||||
|
||||
@ -22,8 +22,9 @@ export default async function RootLayout({
|
||||
let session = null;
|
||||
if (shouldUseSession) {
|
||||
try {
|
||||
const { getSession } = await import('~/auth');
|
||||
session = await getSession();
|
||||
// @ts-ignore - auth module may not exist in all template variants
|
||||
const authModule = eval('require("~/auth")');
|
||||
session = await authModule.getSession();
|
||||
} catch (error) {
|
||||
console.warn('Failed to get session:', error);
|
||||
}
|
||||
|
||||
@ -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>
|
||||
<AuthWrapper>{children}</AuthWrapper>
|
||||
</SafeFarcasterSolanaProvider>
|
||||
</MiniAppProvider>
|
||||
</WagmiProvider>
|
||||
</SessionProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@ -53,7 +74,7 @@ export function Providers({
|
||||
backButtonEnabled={true}
|
||||
>
|
||||
<SafeFarcasterSolanaProvider endpoint={solanaEndpoint}>
|
||||
<AuthKitProvider config={{}}>{children}</AuthKitProvider>
|
||||
{children}
|
||||
</SafeFarcasterSolanaProvider>
|
||||
</MiniAppProvider>
|
||||
</WagmiProvider>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import dynamic from 'next/dynamic';
|
||||
import { useCallback, useState, type ComponentType } from 'react';
|
||||
import { useMiniApp } from '@neynar/react';
|
||||
import { ShareButton } from '../Share';
|
||||
@ -9,14 +10,21 @@ import { type Haptics } from '@farcaster/miniapp-sdk';
|
||||
import { APP_URL } from '~/lib/constants';
|
||||
|
||||
// Optional import for NeynarAuthButton - may not exist in all templates
|
||||
let NeynarAuthButton: ComponentType | null = null;
|
||||
try {
|
||||
const module = require('../NeynarAuthButton/index');
|
||||
NeynarAuthButton = module.NeynarAuthButton;
|
||||
} catch (error) {
|
||||
// Component doesn't exist, that's okay
|
||||
console.log('NeynarAuthButton not available in this template');
|
||||
}
|
||||
const NeynarAuthButton = dynamic(
|
||||
() => {
|
||||
return Promise.resolve().then(() => {
|
||||
try {
|
||||
// @ts-ignore - NeynarAuthButton may not exist in all template variants
|
||||
const module = eval('require("../NeynarAuthButton/index")');
|
||||
return module.default || module.NeynarAuthButton;
|
||||
} catch (error) {
|
||||
// Return null component when module doesn't exist
|
||||
return () => null;
|
||||
}
|
||||
});
|
||||
},
|
||||
{ ssr: false }
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user