Replies: 11 comments 27 replies
-
Hi @bmandl, If you add a file import { Provider } from 'next-auth/client'
// Use the <Provider> to improve performance and allow components that call
// `useSession()` anywhere in your application to access the `session` object.
export default function App ({ Component, pageProps }) {
return (
<Provider session={pageProps.session} >
<Component {...pageProps} />
</Provider>
)
} This will allow your client side rendered page to inherit the session data from the server side rendering pass, so that you don't see a flash of content intended for users who are not signed in. It will also mean the session state is shared between other pages in your site, so when a user navigates to a new page on your site the client won't need to wait to check the session again before displaying the new page. This is a scenario where Single Page Apps are able to be much more responsive to user input and feel faster than traditional web applications because they can take advantage of things like session state already being stored in memory on the client. |
Beta Was this translation helpful? Give feedback.
-
@iaincollins Weird issue, I have got a component and a page, // _app.tsx
import { AppProps } from "next/app";
import { Provider as NextAuthProvider } from "next-auth/client";
import { GeistProvider, CssBaseline } from "@geist-ui/react";
const App: React.FC<AppProps> = ({ Component, pageProps }) => {
return (
<NextAuthProvider session={pageProps.session}>
<GeistProvider>
<CssBaseline />
<Component {...pageProps} />
</GeistProvider>
</NextAuthProvider>
);
};
export default App; Never mind, Found the issue |
Beta Was this translation helpful? Give feedback.
-
@iaincollins Hey, encountering the same issue on page refresh with JWT (SSG/client-side). I notice a flash of my 'login' button even while authenticated in the header. I also have the same setup for I tested the output with I also tested this out with SSR with no issues but atm didn't want to opt in to SSR. Am I missing something or a concept on how this is suppose to work. |
Beta Was this translation helpful? Give feedback.
-
I'm facing the same issue, I had to switch to the |
Beta Was this translation helpful? Give feedback.
-
Similar problem here trying to So, it works well when I work in development, but when I deploy it to Azure in a Docker container I get the following error:
|
Beta Was this translation helpful? Give feedback.
-
I believe I'm experiencing a similar issue. I am using JWT with an otherwise unmodified #704 (comment) is a really good explanation of what's happening - whenever I Could @iaincollins or @balazsorban44 confirm or comment on whether it's normal / expected behaviour for The only thing that fixed this for me was using the Any input / advice would be greatly appreciated! 🙏 |
Beta Was this translation helpful? Give feedback.
-
In the code-comment of header.js it says: "and avoids any flash incorrect content on initial page load". When I reload the page on client-side I actually see for 1 second the Login button even when I am already logged in. What is meant by "flash incorrect content"? Does this mean I HAVE to use SSR to avoid this? How would one build an application with next.js / next-auth and static pages that does not have this behavior of showing an incorrect state until the session is loaded? |
Beta Was this translation helpful? Give feedback.
-
Vercel needs solid patching in regards to ALL of their tech. Too many customized work arounds. Unproductive and time consuming. Probably last time I use next.js for a very very long time. Triple the work with almost close to none performance boost. |
Beta Was this translation helpful? Give feedback.
-
If you're developing locally with JWT enabled, make sure to set a NEXTAUTH_SECRET in your .env (see https://next-auth.js.org/configuration/options) |
Beta Was this translation helpful? Give feedback.
-
Facing this issue even in 2023 with app router. When I reload a page, even when the user is signed in, it shows a flash of logged out screen and then shows the correct screen. Unsure what I am doing wrong. |
Beta Was this translation helpful? Give feedback.
-
Try checking for the loading status AND the session provided by useSession like this
This way the AccessDenied component won't flash when loading/refreshing the page. |
Beta Was this translation helpful? Give feedback.
-
Hello guys,
I am new to next.js and I really started to like it. I am getting used to migrate from express.js routing to next.js api routing (kind of messy, but I am getting there). Now, I am developing simple calendar app, where I want to show login page, if user is not logged in, and calendar with events, if user is logged in. Now, everytime I refresh my page, I see a login page for a short period of time, then session gets populated and I can see my calendar page. Am I missing some optimization here or anything else? Here is snipped of my code:
And my [...nextAuth].js file, just copied from example:
So any ideas, why is this happening to me? What should I do to prevent that, so when I refresh my page, I see Calendar page, because I am already logged in.
Beta Was this translation helpful? Give feedback.
All reactions