-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INCOMPABILITY OF USERPROVIDER WITH NEXT.JS 13 NEW APP DIRECTORY #1309
Comments
Hi @Leonardll, support for the app directory is currently in beta. Check out more info about installing the beta release here: #1235 |
thanks a million @Widcket , have lovely day. :) |
I'm using the pages directory and I get a build error trying to use the useUser() method. 8:41 Error: React Hook "useUser" is called in function "members" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use".
Code that fails:
|
Hi @barnent1 - take another look at your error message
|
exactly my point! useUser is not my function it's AuthO's. it returns {user, error, isLoading} So tell me how is one to use an uppercase when the function is defined in a lowercase? |
Hi @barnent1 - The React component that needs to start with an uppercase letter is your |
Adam, Thank You Very much for pointing out what an IDIOT I am. lol sometimes the most obvious things escape me. I appreciate your tolerance!! Glen |
Checklist
Description
I'm currently using the latest version of Next.js (v13) and the @auth0/nextjs-auth0 package for authentication in my application. I'm experiencing an issue with the UserProvider hook when using the new app directory structure introduced in Next.js 13.
The error message I'm receiving is: Error: You forgot to wrap your app in .
Here's a brief overview of my directory structure:
I have wrapped my application with the UserProvider in my _app.tsx file as follows:
`
import { UserProvider } from "@auth0/nextjs-auth0/client";
function MyApp({ Component, pageProps }) {
return (
<Component {...pageProps} />
);
}
export default MyApp;
`
However, I'm still receiving the error message. I've tried various solutions, including moving the UserProvider to different components and ensuring that the useUser hook is being called within a component that is a child of the UserProvider. However, none of these solutions have resolved the issue.
I suspect that this issue may be related to the new app directory structure in Next.js 13, as the page.tsx file seems to be expected to be the one with the UserProvider.
I would appreciate any guidance or assistance in resolving this issue. Thank you.
Reproduction
Here's a brief overview of my directory structure:
I have wrapped my application with the UserProvider in my _app.tsx file as follows:
`
import { UserProvider } from "@auth0/nextjs-auth0/client";
function MyApp({ Component, pageProps }) {
return (
<Component {...pageProps} />
);
}
export default MyApp;
`
2nd case
app directory
I also tried wrapping the UserProvider in my layout.tsx file
`
import "./globals.css"
import { Inter } from "next/font/google"
import { UserProvider } from "@auth0/nextjs-auth0/client"
const inter = Inter({ subsets: ["latin"] })
export const metadata = {
title: "Create Next App",
description: "Generated by create next app",
}
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
{children}
)
}
3rd case i have also tried to create a custom hook and wrap my page.tsx component with it as follow
// hooks/useAuthUser.tsx
import { useUser, UserProvider } from "@auth0/nextjs-auth0/client";
import { FC, ReactNode } from "react";
export const useAuthUser = () => {
const { user, error, isLoading } = useUser();
return { user, error, isLoading };
};
interface AuthUserProviderProps {
children: ReactNode;
}
export const AuthUserProvider: FC = ({ children }) => {
return {children};
};
`
However, I'm still receiving the error message. I've tried various solutions, including moving the UserProvider to different components and ensuring that the useUser hook is being called within a component that is a child of the UserProvider. However, none of these solutions have resolved the issue.
I suspect that this issue may be related to the new app directory structure in Next.js 13, as the page.tsx file seems to be expected to be the one with the UserProvider.
I would appreciate any guidance or assistance in resolving this issue. Thank you.
Additional context
typescript
nextjs-auth0 version
@auth0/nextjs-auth0
Next.js version
13.4.1
Node.js version
18.12.0
The text was updated successfully, but these errors were encountered: