Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

How to show a dynamic user profile in the header while keeping a statically generated page in Next with Auth.js (without PPR)

61,186 görüntüleme • 1 yıl önce •via X (Twitter)

10 Yorum

Alex Sidorenko profil fotoğrafı
Alex Sidorenko1 yıl önce

Explanation: Server side auth check - "await auth()" opts the entire page into a dynamic rendering. Most of the time it's fine, as you likely use some user specific content on the page, so it will be dynamic anyway. However, sometimes you might want to combine the dynamic user profile in the header with a static page (example: landing page). The simplest way to do this right now, is to use the client version of auth. In case of Auth.js it's useSession hook. By using this hook you tell the component to send a request to "api/auth/session" on the client to get user data. This way we can keep the underlying page static. P.S. You can use server side auth - "await auth()" with static page using PPR. Just wrap the dynamic part with Suspense and Next will statically generate entire page and dynamically stream in the Suspense bit. But PPR is still experimental.

eSignatures.com profil fotoğrafı
eSignatures.com1 yıl önce

Discover Add secure, embedded signing to your WordPress site in seconds. Try now!

Morpheus profil fotoğrafı
Morpheus1 yıl önce

How do you get that static route notification at the bottom left?

Manu profil fotoğrafı
Manu1 yıl önce

must admit that it took me a while to understand that passing a server component as a prop/child to a client component is a trick to avoid moving the client boundary.

Madat Bayramov profil fotoğrafı
Madat Bayramov1 yıl önce

What page type you get after building next app? In my case I’m also using the same logic. Root layout has session provider component that wraps all children. Even static pages under that layout are built as dynamic (with f flag instead of cycle)

夜奏花 profil fotoğrafı
夜奏花1 yıl önce

What’s the difference between

Alex Sidorenko profil fotoğrafı
Alex Sidorenko1 yıl önce

Between what and what?

Raqib Nur profil fotoğrafı
Raqib Nur1 yıl önce

It’s a must-have. I’ve seen someone raise an issue about it.

Abdalrahman Mahmoud profil fotoğrafı
Abdalrahman Mahmoud1 yıl önce

hey a quick question why does it matter if the page is statically or dynamically generated?

Alex Sidorenko profil fotoğrafı
Alex Sidorenko1 yıl önce

Static pages are faster and cheaper. Next, pre-generate HTML (during the build time) that can be served via CDN close to your users. Plus, it reduces the server load/hosting costs, as you don't need to re-render a page on the server on every request.

Benzer Videolar