-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Inconsistent session returns after 3.8.0 #1461
Comments
Interesting, I unfortunately managed to reproduce it and I'll try to identify the source of the problem! Thanks for reporting! |
My best guess is that one of the build dependencies changed between 3.7.1 and 3.8.0 and the transpiler introduced a new bug as a result. Check out the diff between 3.7.1 and the actual packages:
|
I am pretty sure this was introduced in 3aee24b. Made some significant changes to clean things up and re-use the session object if it was passed. It might have had unforeseen consequences. I am afraid that I did not fix #1084 after all.. UPDATES:
|
🎉 This issue has been resolved in version 3.10.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
So this should be fixed now in @theycallmeswift could you confirm that this has indeed been fixed for now? |
omg lol I just uprooted my entire application trying to figure out what I broke and realized that it was 3.10.0 that caused it. so glad I stumbled upon this post. Any side effects to the dirty fix you mention? |
Not really, it was an optimization that did not work as intended. Reverted to how it worked before. In short, if you pass session to UPDATE: Here is my PR #1473 |
Hey! First: love the work! I'm still having this issue @3.23.3 |
Please open a new issue, with a reproduction. |
https://github.com/filipesmedeiros/nano-medium-poc/tree/show-next-auth-bug This branch has the bug working. If you login using Github (sorry to force this, can I make it like a mock session? If you don't want to login), and then go to the "New Post" page, when you press "Publish" it will fail with You can see in the source that If you go to the Let me know if you need anything else! EDIT: Btw, I'm running it with |
I am not convinced this is still an issue. Could you please open a completely new issue with your bug report and a detailed explanation instead of a new comment here? Thanks! |
**What**: These changes ensure that we work more tightly with React that can also result in unforeseen performance boosts. In case we would decide on expanding to other libraries/frameworks, a new file per framework could be added. **Why**: Some performance issues (#844) could only be fixed by moving more of the client code into the `Provider`. **How**: Refactoring `next-auth/client` Related: #1461, #1084, #1462 BREAKING CHANGE: **1.** `next-auth/client` is renamed to `next-auth/react`. **2.** In the past, we exposed most of the functions with different names for convenience. To simplify our source code, the new React specific client code exports only the following functions, listed with the necessary changes: - `setOptions`: Not exposed anymore, use `SessionProvider` props - `options`: Not exposed anymore, use `SessionProvider` props - `session`: Rename to `getSession` - `providers`: Rename to `getProviders` - `csrfToken`: Rename to `getCsrfToken` - `signin`: Rename to `signIn` - `signout`: Rename to `signOut` - `Provider`: Rename to `SessionProvider` **3.** `Provider` changes. - `Provider` is renamed to `SessionProvider` - The `options` prop is now flattened as the props of `SessionProvider`. - `clientMaxAge` has been renamed to `staleTime`. - `keepAlive` has been renamed to `refetchInterval`. An example of the changes: ```diff - <Provider options={{clientMaxAge: 0, keepAlive: 0}}>{children}</Provider> + <SessionProvider staleTime={0} refetchInterval={0}>{children}</SessionProvider> ``` **4.** It is now **required** to wrap the part of your application that uses `useSession` into a `SessionProvider`. Usually, the best place for this is in your `pages/_app.jsx` file: ```jsx import { SessionProvider } from "next-auth/react" export default function App({ Component, pageProps: { session, ...pageProps } }) { return ( // `session` comes from `getServerSideProps` or `getInitialProps`. // Avoids flickering/session loading on first load. <SessionProvider session={session}> <Component {...pageProps} /> </SessionProvider> ) } ```
**What**: These changes ensure that we work more tightly with React that can also result in unforeseen performance boosts. In case we would decide on expanding to other libraries/frameworks, a new file per framework could be added. **Why**: Some performance issues (nextauthjs#844) could only be fixed by moving more of the client code into the `Provider`. **How**: Refactoring `next-auth/client` Related: nextauthjs#1461, nextauthjs#1084, nextauthjs#1462 BREAKING CHANGE: **1.** `next-auth/client` is renamed to `next-auth/react`. **2.** In the past, we exposed most of the functions with different names for convenience. To simplify our source code, the new React specific client code exports only the following functions, listed with the necessary changes: - `setOptions`: Not exposed anymore, use `SessionProvider` props - `options`: Not exposed anymore, use `SessionProvider` props - `session`: Rename to `getSession` - `providers`: Rename to `getProviders` - `csrfToken`: Rename to `getCsrfToken` - `signin`: Rename to `signIn` - `signout`: Rename to `signOut` - `Provider`: Rename to `SessionProvider` **3.** `Provider` changes. - `Provider` is renamed to `SessionProvider` - The `options` prop is now flattened as the props of `SessionProvider`. - `clientMaxAge` has been renamed to `staleTime`. - `keepAlive` has been renamed to `refetchInterval`. An example of the changes: ```diff - <Provider options={{clientMaxAge: 0, keepAlive: 0}}>{children}</Provider> + <SessionProvider staleTime={0} refetchInterval={0}>{children}</SessionProvider> ``` **4.** It is now **required** to wrap the part of your application that uses `useSession` into a `SessionProvider`. Usually, the best place for this is in your `pages/_app.jsx` file: ```jsx import { SessionProvider } from "next-auth/react" export default function App({ Component, pageProps: { session, ...pageProps } }) { return ( // `session` comes from `getServerSideProps` or `getInitialProps`. // Avoids flickering/session loading on first load. <SessionProvider session={session}> <Component {...pageProps} /> </SessionProvider> ) } ```
Describe the bug
A bug was introduced starting in 3.8.0 that prevents the session from being read multiple times. If you have multiple components that rely on the
useSession
hook, only the first one will return a session object as expected.Steps to reproduce
You can introduce this behavior to the next-auth-example with the following diff. Changes added to
pages/index.js
are for easy visibility.Expected behavior
Note: This works as expected with 3.7.1 and below.
Actual behavior
Note: The session works as expected for the header but returns an empty object the second time the hook is used.
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
The text was updated successfully, but these errors were encountered: