How to display component only to logged in users?

I have an LW component which I want to show only to the logged-in users.
I can do it from out side the component by wrapping it within @auth() and @endauth directive.
How can I render or not, based on a condition within the component if that makes sense?

@auth()
    @livewire('my-component')
@endauth

You can do the same inside of you component view, just remember you need a div wrapping it all for livewire to attach an id to.

<div>
    @auth()
       ...
    @endauth
</div>

Yes but that would boot up the component. Iā€™m Looking for something that can check a condition and based on that, the component gets mounted or not.

@auth()
    @livewire('my-component')
@endauth

Otherwise wrapping the component in a condition is better but I have to make sure every time I use it I must wrap it inside the component.

The only ways I can come up with to gracefully do it inside of the component (without an overhaul to the core) either still requires something outside of the component as well, or still boots the component. I think you might be limited to one of our two ideas here.

1 Like

Agree. So I went with wrapping the component inside a condition.

Thanks for your time.