koole / react-sanctum

Easily hook up your React app to Laravel Sanctum and Laravel Fortify
MIT License
152 stars 26 forks source link

Load user data before page load #186

Closed harrisonratcliffe closed 1 year ago

harrisonratcliffe commented 1 year ago

Is there any way for the user data to be fetched before the page loads? I've got the users name on the homepage and its briefly undefined until the page finishes loading.

koole commented 1 year ago

Yep, if you read the value of the authenticated variable in the SanctumContext, you can check if it's null. Put an if statement around the parts you want wait to render with a check if this variable is null.