I have a NextJs application with its back-end in Laravel.
All of our Laravel api routes are protected with Laravel Sanctum to prevent XSS attacks.
The problem is that this auth method relies on sending cookies with each request. So when I try to make these requests from getStaticProps function, I do not have cookies available.
What is best practice for this scenario? Disable sanctum for the specific routes needed in getStaticProps? Or is there some black magic that will help me retrieve the needed cookies?
This is a toughie! Unfortunately it is a bit of an anti-pattern to have auth locked content and static content in the same conversation because static data usually shouldn't depend on dynamic data if that makes any sense. You might be able to find some more information here in case it's helpful however: Next.js withPageAuthRequired with getStaticProps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With