I'm currently moving my side project, built on the Tall stack preset over to Jetstream and all is good. The only issue I'm running into is Fortify's Auth system. I have one important section on my site that requires Guests to login in.
//TEST PAGE
@guest
Please login or register
<a href="{{ route('login') }}">Login</a>
<a href="{{ route('register') }}">Register</a>
@endif
Now you can proceed.
Once they login/register I need them to return back to this page. But with Jetstream & Fortify there is no Login/Register controller or Action available. They are hidden in the Vendor Files =/
If the Route is protected with middleware I can get it to work, but in this "use case" it's not acceptable for this section.
//Redirects Back To Intended URL
Route::middleware(['auth:sanctum', 'verified'])->get('test',[App\Http\Controllers\TestController::class, 'test'])->name('test');
//Does NOT Redirects Back To Intended URL
Route::get('test',[App\Http\Controllers\TestController::class, 'test'])->name('test');
JetStream: Middleware\RedirectIfAuthenticated.php
public function handle($request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return Redirect::intended('/');
// return redirect(RouteServiceProvider::HOME);
}
}
return $next($request);
}
On Laravel 7 Tallstack it worked great like this with the Livewire Login Component:
public $previousUrl='/';
public function mount ()
{
$this->previousUrl=\session('_previous.url');
}
public function authenticate()
{
$credentials = $this->validate([
'email' => ['required', 'email'],
'password' => ['required'],
]);
if (!Auth::attempt($credentials, $this->remember)) {
$this->addError('email', trans('auth.failed'));
return;
}
redirect()->to($this->previousUrl);
// redirect(route('home'));
}
I realize Jetstream is brand new to the scene and I probably should have waited, but this is the only thing holding me back.
I did find this Workaround/Hack that might possibly work, but really hoping for a better solution
Link: https://github.com/laravel/jetstream/issues/102#issuecomment-689664204
If someone could please help me get this working I would really appreciate it.