Centralize Authentication Logic for Maintainable Next.js CodeCentralize Authentication Logic for Maintainable Next.js Code
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
Same task. Two approaches. Which one would you choose? 👇 Look at the screenshot: 🔴 LEFT SIDE: The developer directly accesses the access_token cookie using cookies() inside the page and passes it to getUsers(). 🟢 RIGHT SIDE: The developer uses a reusable getAccessToken() function from a centralized authentication module. Why does the right-side approach matter? Because of DRY - Don't Repeat Yourself. Instead of repeating authentication logic across multiple pages, we centralize it into a reusable function. Benefits? Less duplicated code. Easier maintenance. Consistent authentication logic. Changes can be handled in one place. But remember, abstraction should make code easier to understand, not hide complexity. I use AI to discuss approaches, question suggestions, review implementations, and improve code before pushing it. AI can write the code. Engineering judgment decides how that code should be built. Building a product? Let's talk about how we can build it right, not just build it fast. #SoftwareEngineering #NextJS #CleanCode #DRYPrinciple #AIDevelopment #WebDevelopment
Post image
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started