hoangvvo / nextjs-mongodb-app

A Next.js and MongoDB web application, designed with simplicity for learning and real-world applicability in mind.
https://nextjs-mongodb.now.sh/
MIT License
1.54k stars 289 forks source link

Can we make api/auth smoother when refresh page ? #65

Closed IRediTOTO closed 4 years ago

IRediTOTO commented 4 years ago

Is your feature request related to a problem? Please describe. image Let's see this image Is there anyway to make refresh page but logged in user will not see the "Hello strenger"? I mean check login from server, not fetch swr from client.

IRediTOTO commented 4 years ago

ops, image above not a gif, lets see this https://i.imgur.com/CvN6m50.gifv

IRediTOTO commented 4 years ago

I found it https://www.npmjs.com/package/next-connect#methodpattern-fns But look like it will make loading slower right?

export async function getServerSideProps({ req, res }) {
   const handler=nextConnect();
   handler.use(middleware)
   handler.use(passport.initialize())

   await  handler.apply(req,res)
   console.log("user",req.user)
   return {
      props: {
         user:req.user,
      },
   };
}
wortkotze commented 4 years ago

i'm using https://www.npmjs.com/package/react-loading-skeleton to create a loading screen at the moment and we try to prefetch and have a service worker in place for caching.

if I use serverSideprops we are running into deployment issues on zeit after their new limits. so we are searching for new ways to deploy next completely to aws by our own

IRediTOTO commented 4 years ago

@wortkotze You r right. I should do like that. Thanh you :)