Is NextAuth.js necessary for Next.js (SSR) e-commerce site authentication with Laravel API?

I’m working on an e-commerce site that needs to be SEO-friendly. I usually use Inertia.js, React, and Laravel for SPAs, but that’s not great for SEO. So now I’m trying Next.js with SSR and a Laravel API.

I’ve seen some stuff online about using NextAuth.js with a Laravel API for Next.js (SSR) authentication. But I’m not sure if it’s really better than just using the Laravel API directly for auth.

I’m wondering:

  1. Do I really need NextAuth.js for this setup, or should I just authenticate directly with the Laravel API?

  2. What’s the advantage of using NextAuth.js with Laravel instead of doing the authentication myself in Next.js?

Any advice would be really helpful. Thanks!

In my experience, NextAuth.js isn’t strictly necessary for a Next.js SSR e-commerce site using a Laravel API. I’ve successfully implemented authentication directly with Laravel in similar projects.

The main advantage of NextAuth.js is its flexibility and built-in support for various authentication providers. However, if you’re only using Laravel’s authentication system, it might be more straightforward to handle it directly.

For SSR, you can use Laravel Sanctum or Passport to generate and validate tokens. Then, store these securely in HTTP-only cookies. This approach provides good security and works well with SSR.

One challenge to watch out for is keeping the authentication state in sync between the server and client. You’ll need to carefully manage this to ensure a smooth user experience.

Ultimately, the choice depends on your specific requirements and comfort level with each approach.

hey, nextauth.js isnt a must if ur auth needs are basic. laravels built in auth often does the trick when combined with proper session managemnt in next.js. maybe try jwt tokens for the ssr setup if u feel that fits ur need.

Hey there WittyCodr99! Interesting question you’ve got there about NextAuth.js and Laravel. I’ve actually been tinkering with a similar setup recently.

Have you considered the trade-offs between using NextAuth.js and going direct to your Laravel API? I’m curious about your specific auth requirements. Are you dealing with social logins or just standard email/password?

From my experience, NextAuth.js can be super handy for complex auth scenarios, but it might be overkill if your needs are straightforward. Have you run into any specific challenges trying to authenticate directly with Laravel?

Also, how are you handling session management on the Next.js side? That’s always been a bit tricky for me with SSR setups.

Would love to hear more about your project and what you end up deciding! Maybe we can learn from each other’s experiences?