You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello and thanks in advance for taking a look at this issue. I am using nextAuth for authentication and would like to show pages based on user authentication. Upon running this code below, it returns 'undefined' for session. However, I followed the docs provided by nextAuth, and don't see any reason why the session would be 'undefined'. Can you help debug?
import Head from 'next/head';
import { getSession } from 'next-auth/react';
import Dashboard from './dashboard';
export default function Home({ session }) {
console.log('SESS', session); //returned 'undefined'
if (!session) {
return (
<div className="">
<Head>
<title>Some Title</title>
<meta
name="description"
content=""
/>
<link rel="icon" href="/favicon.ico" />
</Head>
<div className="">
<main className="bg-gradient-to-r from-gray-50 via-slate-300 to-gray-50 pb-6">
<div> This shows if there is no session </div>
</main>
</div>
</div>
);
}
return <Dashboard />;
}
export async function getServerSideProps(context) {
const session = await getSession(context);
console.log(session) // logs out session successfully.
return {
props: {
session,
},
};
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello and thanks in advance for taking a look at this issue. I am using nextAuth for authentication and would like to show pages based on user authentication. Upon running this code below, it returns 'undefined' for session. However, I followed the docs provided by nextAuth, and don't see any reason why the session would be 'undefined'. Can you help debug?
Beta Was this translation helpful? Give feedback.
All reactions