Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

n8udd's avatar
Level 12

benefits/pitfalls of `useAuth` Context over `useAuth` hook with Breeze and Sanctum API

I'm currently working on an API with Sanctum and I'm using the NextJS Breeze front end.

_Please excuse me if this is a stupid question... _

I'm using the the useAuth hook that Taylor/Mohamed Said created, and optional chaining the user?. , but in some cases such as my nav that loads conditionally based on the user's role, it delays the load/jumps the page.

Is there any reason not to pass the Auth()::user() back using getServerSideProps instead, and validating that this user can see the menu nav?

I'm meaning "any reason" from a security point of view. I've eager loaded the roles on the user model, and I return that in the useAuth hook along with an isAdmin method, but the SSR for user (which could be combined with an AuthUser Context Provider could be a cleaner option.

0 likes
0 replies

Please or to participate in this conversation.