Загрузка видео...

Не удалось загрузить видео

На главную

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 просмотров • 1 год назад •via X (Twitter)

Комментарии: 10

Фото профиля Alex Sidorenko
Alex Sidorenko1 год назад

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
eSignatures.com1 год назад

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

Фото профиля Morpheus
Morpheus1 год назад

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

Фото профиля Manu
Manu1 год назад

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
Madat Bayramov1 год назад

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)

Фото профиля 夜奏花
夜奏花1 год назад

What’s the difference between

Фото профиля Alex Sidorenko
Alex Sidorenko1 год назад

Between what and what?

Фото профиля Raqib Nur
Raqib Nur1 год назад

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

Фото профиля Abdalrahman Mahmoud
Abdalrahman Mahmoud1 год назад

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

Фото профиля Alex Sidorenko
Alex Sidorenko1 год назад

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.

Похожие видео