I have a custom auth login in laravel 5.2, my config for custom login is
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'provider' => [
'driver' => 'session',
'provider' => 'providers',
],
],
I have two auth controllers, One is laravel AuthController and other is ProviderAuthController. I have set SESSION_DRIVER=database in my env and also created a session table in my database I am getting sessions from web login but problem is that I am not able to get sessions on provider login. Is there any workaround to insert session on provider login.
There is nothing in my app service provider
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
The route for my providerAuthcontroller are Route::group(['prefix' => 'provider'], function(){
Route::get('login', 'Auth\ProviderAuthController@showLoginForm');
Route::post('login', 'Auth\ProviderAuthController@login');
Route::get('logout', 'Auth\ProviderAuthController@logout');
// Registration Routes...
Route::get('register', 'Auth\ProviderAuthController@showRegistrationForm');
Route::post('register', 'Auth\ProviderAuthController@register');
// Password Reset Routes...
Route::get('password/reset/{token?}', 'Auth\ProviderPasswordController@showResetForm');
Route::post('password/email', 'Auth\ProviderPasswordController@sendResetLinkEmail');
Route::post('password/reset', 'Auth\ProviderPasswordController@reset');
Its supposed to happen in the middlewares, not in the providers.
Route::get('profile', function () {
// Only authenticated users may enter...
})->middleware('auth');
and
class Auth
{
public function handle(\Illuminate\Http\Request $request, Closure $next)
{
if(!$request->session()->get('authenticated'){
throw AuthException();
}
return $next($request);
}
}
Also check laravel lifecycle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With