next-auth: [next-auth]: `useSession` must be wrapped in a pages folder move to inside src folder-
Description ๐
Moving pages folder to src. Getting error [next-auth]: useSession must be wrapped in a <SessionProvider />.
Working fine when pages folder on root dir.
Is this a bug in your own project?
No
How to reproduce โ๏ธ
Move pages folder to inside src folder mkdir src move pages to src dir
Screenshots / Logs ๐ฝ
PFA - Error

Environment ๐ฅ
System: OS: macOS 11.3.1 CPU: (8) arm64 Apple M1 Memory: 128.27 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.8.0 - /opt/homebrew/bin/node Yarn: 1.22.11 - /opt/homebrew/bin/yarn npm: 7.21.0 - /opt/homebrew/bin/npm Browsers: Chrome: 95.0.4638.54 Edge: 92.0.902.67 Safari: 14.1 npmPackages: next: 12.0.1 => 12.0.1 next-auth: ^4.0.0-beta.5 => 4.0.0-beta.5 react: 17.0.2 => 17.0.2
Contributing ๐๐ฝ
No, I am afraid I cannot help regarding this
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (4 by maintainers)
In my case, the problem was related to cache. I deleted the .next folder and worked.
For someone that use nextjs 13. CC @mosgizy @thadeubrito Mine is working after make a new
SessionProvidercomponents like this:And then wrap the most outer layout or root layout that usually placed in here
/src/app/layout.tsxusing that component like this:iโm having this issue with nextjs 13 gone through series of ways to fix it but still the same
Then thatโs the issue. Your
SessionProviderhas to come beforeLayoutWrapper.its working for me
you just saved me hours of frustrationโฆ thank you!
I just changed my
_app.jsto this:still same error, I am using
useSessionin my LayoutWrapper component.the error appears wherever (in any components) I import this:
import { signIn, signOut, useSession } from 'next-auth/react'and use this before return:
const { data: session, status } = useSession()could you please share your
_app.tsxfile?