What's new

PHP Laravel 8 Livewire Middleware (Authentication)

REN31

Addict
Joined
Oct 14, 2016
Posts
26
Reaction
2
Points
75
Age
24
Tanong lang sa Livewire Components.
Paano po ang user auth every method then mag redirect siya sa login during runtime?
Naiisip ko po na pa middleware yung way.
Pero yung default na middleware ng laravel na authenticate na ->middleware('auth')
at kahit na custom na middleware na nilalagay sa routes ay nagana lang po sa pag ni load na ang page
at nagre redirect naman siya sa login pag di pa naka signin ang user.
Pero di na nagana pagkatapos ma load ang page.

Like pag naka open na po sa dalawang tab ang webpage at nakaaccess sa main page.
Then na logout na sa isang tab.
Then niaccess yung padalawang tab na nasa mainpage padin ay di siya nagre redirect sa login page pagkatapos maclick ang isang button na nag titrigger sa isang method ng component.
Nag authenticate naman po sa background yung middleware pero hindi na load yung login page sa browser at nasa network lang siya nag render sa developer options.
 
show your source code
->middleware('auth') it should working on your route
btw. medyo di ko gets yung tanong mo hahaha
di ko gets ung saktong gusto mong mangyare
 
1625280238950.png


1625280307738.png


1625281106454.png


1625281147372.png


1625281322027.png


1625281247073.png


then pag ka click sa isa sa mga nav ay di siya nag reredirect sa login page
pero nag load lang siya sa background

1625281424065.png
 

Attachments

try mo add to sa MainLivewire mo

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class MainLivewire extends Component
{
use AuthorizesRequests;
public function change_tab($page)
{
$this->$page = $page
$this->authorize('update', $this->update_url());
}
//code
}

di ko sure kung gagana to
pero try mo muna
di kase ako gumagamit ng livewire
more on vue.js ako e
 
try mo add to sa MainLivewire mo

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class MainLivewire extends Component
{
use AuthorizesRequests;
public function change_tab($page)
{
$this->$page = $page
$this->authorize('update', $this->update_url());
}
//code
}

di ko sure kung gagana to
pero try mo muna
di kase ako gumagamit ng livewire
more on vue.js ako e
Nakikita ko po din tong authorize na to.
Ano po ba ang logic nito?
Di ko po magets ang paramaters niya.
Sa eloquent o database po ba to?
 
Last edited:
okke
eto payo ko sayo
since gumamit ka ng switch case para di na mag reload ung page mo pag lilipat ka ng tab
at gumamit ka ng middleware, hindi tlga mag re-refresh ung page o mag re-redirect sa ibang page pag namatay ung session mo
once na na-logout na ung kabilang tab
mamamatay na ung user session mo
pag namatay na ung session di na magiging clickable si livewire
so khit anong click mo sa tab di nya gagawin ung nasa MainLiveWire o yung change_tab function mo

so the best way is mag 1 page 1 component ka
 
Back
Top