-
Question 💬Is it possible to make next-auth work in static pages with revalidation ? Expected behavior: Current behavior:
Again - this happens when the page has You can find link to my repo below (and on file names) in case you want to test it out (need to have it compiled) function MyApp({ Component, pageProps, session }: AppProps & CustomProps) {
return (
<>
<SessionProvider session={session}>
<Component {...pageProps} />
</SessionProvider>
</>
);
}
MyApp.getInitialProps = async (appContext: AppContext): Promise<AppInitialProps & CustomProps> => {
const appProps = await App.getInitialProps(appContext);
const session = (await getSession(appContext.ctx)) as Session;
return { ...appProps, session };
}; const Home: NextPage = (props) => {
const { data: session } = useSession();
const userName = session?.user?.name;
const button = session ? (
<button onClick={() => signOut()}>Sign out</button>
) : (
<button onClick={() => signIn()}>Sign in</button>
);
let userSession = (
<div>
<p>You are not logged in</p>
</div>
);
if (session) {
userSession = (
<div>
<p>You are logged in as: {userName}</p>
</div>
);
}
return (
<div>
{button}
{userSession}
<div>from getStaticProps: {(props as any).timestamp}</div>
<div>client: {new Date().toISOString()}</div>
</div>
);
};
export async function getStaticProps() {
return {
props: {
timestamp: new Date().toISOString(),
},
revalidate: 1,
};
}
... How to reproduce ☕️Can clone my repo : https://github.com/callmegin/next-auth-test Contributing 🙌🏽No, I am afraid I cannot help regarding this |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Just checking in to see if there's anything else that I can do over here to get some ideas regarding my question? |
Beta Was this translation helpful? Give feedback.
-
If someone will ever end up on this question, here's an answer from Next-Auth maintainer: vercel/next.js#34316 (comment) |
Beta Was this translation helpful? Give feedback.
If someone will ever end up on this question, here's an answer from Next-Auth maintainer: vercel/next.js#34316 (comment)