Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling auth inside getStaticProps requests

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?

like image 238
Juan Chaher Avatar asked Aug 04 '26 01:08

Juan Chaher


1 Answers

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.

like image 189
Amit Maraj Avatar answered Aug 05 '26 16:08

Amit Maraj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!