<AuthLoading>
The <AuthLoading>
component renders its children only during an authentication session loading. This provides an easy way for you to insert loading states or skeleton loaders into your UI, enhancing user experience during data fetching.
Usage
Wrap loading placeholders or loader components with <AuthLoading>
to conditionally render them whenever authentication session data is being fetched.
Example
Here's a complete example of using <AuthLoading>
with loading skeletons and managing unauthenticated user sessions using the <RedirectToSignIn />
and <SignedIn>
components.
Explanation
<AuthLoading>
will render the loading skeleton (<YourCustomSkeleton />
) while authentication or session data is initializing or fetching.<RedirectToSignIn>
automatically pushes any unauthenticated users to the sign-in page, ensuring pages that require authentication are protected from unauthorized access.<SignedIn>
ensures the enclosed content (<DashboardContent />
) only displays for authenticated users.
This combined approach offers seamless handling of loading states, authentication redirection, and conditional rendering based on user authentication state, greatly improving the overall user experience.
Skeleton Loaders
In practice, your skeleton loader will likely be customized. Here's a basic example you can easily customize to fit your use-case:
This example skeleton provides placeholder components resembling the size and shape of loaded content, greatly reducing UI flicker and enhancing user-perceived loading performance.