NextJS: 03-09 Set Protected Pages to be accessed only when logged in

Опубликовано: 21 Май 2026
на канале: Easy Frontend
3,516
62

When the project has some pages that require login to view the content, how will I set it up? 🤔

Use useAuth hook
Create a component to manage rendering depending on logged in user

Slide: https://drive.google.com/drive/folder...
———
#nextjs
#protected_pages
#nextjs_tutorial
———
VIDEO CHAPTERS:
Made by: Sinh Bui Dinh
Thank you very much! ❤️

00:14 Introduce install component AUTH for (Protected Pages)
00:40 Explain setting page per page
01:40 Explain setting by Layout
02:15 Setting common component AUTH
05:55 Idea check first loading in hook
07:10 Handle protect page when loading done
09:00 Flow checks page about working with protect page
12:10 Handle act when login success for see full thread protected page
13:10 Apply Logout in layout has protected page
14:50 Good points of SWR
15:40 Issue when trying to access protected page by router.push
16:15 Different between access protect page by router.push from login after logout instead go direct
17:20 Test all threads
17:50 Test case apply mutate = null instead of {} when logout
18:35 Test case apply mutate = undefined instead of {} when logout
19:55 How to apply protect page
———
Easy Frontend - Better code every day
🔥 Javascript course: https://course.ezfrontend.com/javascript
🎁 ReactJS course: https://course.ezfrontend.com/reactjs
🎯 Easy Frontend fan:    / @easyfrontend  
———
💰 Support me in making videos, please donate via MoMo/ZaloPay: 0901 309 729
———
Connect with me:
✅ Follow facebook:   / nvhauesmn  
🎉 Fan page:   / learn.easyfrontend  
❓ Group:   / easyfrontend  
💻 Github: https://github.com/paulnguyen-mn
💼 LinkedIn:   / haunguyenmn