farcasterxyz / auth-monorepo

Farcaster Auth monorepo
MIT License
46 stars 33 forks source link

createContext is not a function when trying to implement on Nextjs14 #229

Open GFialho opened 3 weeks ago

GFialho commented 3 weeks ago

I am trying to implement AuthKitProvider on NextJs 14.2.4 but I'm having this error when adding AuthKitProvider:

TypeError: (0 , react__WEBPACK_IMPORTED_MODULE_2__.createContext) is not a function

This is my code:

import "@farcaster/auth-kit/styles.css";

import { AuthKitProvider } from "@farcaster/auth-kit";

const config = {
  relay: "https://relay.farcaster.xyz",
  rpcUrl: "https://mainnet.optimism.io",
  siweUri: "http://example.com/login",
  domain: "example.com",
};

export default async function FarcastProvider({
  children,
}: {
  children: React.ReactNode;
}) {
  return <AuthKitProvider config={config}>{children}</AuthKitProvider>;
}

And I am adding it on may layout.tsx

      <RootStyleRegistry>
          <Theme>
            <ContextProvider cookies={cookies}>
              <ClientProvider session={session}>
                <FarcastProvider>
                  <SolWalletProvider>
                    <EvmWalletProvider>
                      <ApolloWrapper>
                        <WalletManagerProvider>
                          <SolWalletManagerProvider>
                            {children}

                            <IntercomComponent />
                          </SolWalletManagerProvider>
                        </WalletManagerProvider>
                      </ApolloWrapper>
                    </EvmWalletProvider>
                  </SolWalletProvider>
                  <Toaster />
                </FarcastProvider>
              </ClientProvider>
            </ContextProvider>
          </Theme>
        </RootStyleRegistry>
evanryuu commented 4 days ago

Hi GFialho, have you tried add 'use client' on top of your FarcastProvider.tsx file?

If the question still exists, check the app/api/auth/[...nextauth]/route.ts file. See if the createAppClient, viemConnector are imported from @farcaster/auth-kit. If they are, import them from @farcaster/auth-client.

I hope these could resolve the problem for you.