FOUC when I try the getServerSideProps example #4675
-
If I follow the example here https://next-auth.js.org/tutorials/securing-pages-and-api-routes#server-side using this specific code: import { useSession, getSession } from "next-auth/react"
import { useRouter } from 'next/router'
import { GetServerSideProps } from 'next'
import { LandingPage } from '@/components'
export default function PageIndex() {
const { data: session } = useSession()
const router = useRouter()
if (session && typeof window !== 'undefined') {
router.push('/dashboard')
}
if (!session) return <LandingPage />
}
export const getServerSideProps: GetServerSideProps = async (context) => {
return {
props: {
session: await getSession(context),
},
}
} And I am logged in. The app will redirect me to I can do something like this: export default function PageIndex({ isLoggedIn }) {
// ...
}
export const getServerSideProps: GetServerSideProps = async (context) => {
const session = await getSession(context)
return {
props: {
session,
isLoggedIn: Boolean(session),
},
}
} I've also tried the Not sure if my implementation is messed up: function Auth({ children }: AuthProps) {
const { status } = useSession()
const router = useRouter()
if (status === 'loading') return null
if (status !== 'authenticated') {
router.replace('/')
}
return children
} Any help would be appreciated. Love this plugin but this little route flash is driving me crazy. 😄 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I also had the same problem and this is how I did it.
` |
Beta Was this translation helpful? Give feedback.
I also had the same problem and this is how I did it.
`