DEV Community

Discussion on: Authentication in Next.js apps

Collapse
 
mroobert profile image
Robert Mihai

Nice article. I was wondering how you could fetch new data besides the user in SSR for a page if you set:
"
// some-page.tsx
export const getServerSideProps = getUserFromServerSession({
redirectToLogin: true,
});
"
It wouldn't be a bit tricky?

Collapse
 
tmaximini profile image
Thomas Maximini

Hey - sorry for the late reply.
If you want to fetch custom data for a certain route you would just have a custom getServerSideProps for that page. Or you can adjust and rename getUserFromServerSession if you intend to fetch the same data on the server for multiple routes. The above was just one example how to you can refactor and reuse getServerSideProps for a couple of pages.