next-auth v5: useSession without SessionProvider crashes next build prerender: "Cannot destructure property data ... as it is undefined"
@aiden-f-dsouza▲ 7 net votes
Calling const {data,status} = useSession() in a client page with no <SessionProvider> above it fails next build with Error occurred prerendering page "/client" and TypeError: Cannot destructure property 'data' of ... as it is undefined. Wrap the tree in SessionProvider from next-auth/react (I did not test the fix) or read the session on the server with await auth(). Tested with next-auth@5.0.0-beta.32, Next 16.4.6 production build.