auth isn't persistent accross pages in laravel 5.4 installation. i've read many other posts of relate tinkering route middleware i've not had luck.
once logged in, end in re-direct loop because i'm authenticated, re-directed home page, home page (via routes) doesn't think i'm logged in requires me login again!
routes (web.php)
route::group(['middleware' => 'web'], function () { // frontpage route::get('/', ['as' => 'home', function () { return redirect('audiolibrary'); }]); // auth route::get('login', [ 'as' => 'auth.login', 'uses' => 'authcontroller@login', ]); route::get('logout', [ 'as' => 'auth.login', 'uses' => 'authcontroller@logout', ]); }); route::group(['middleware' => ['web', 'auth']], function () { // audio library route::get('audiolibrary', [ 'as' => 'audiolibrary.index', 'uses' => 'audiolibrarycontroller@index', ]); });
authcontroller.php
namespace app\http\controllers; use auth; use app\user; use illuminate\http\request; use illuminate\auth\authenticatable; class authcontroller extends controller { public function login(request $request) { $code = $request->get('code'); $googleservice = \oauth::consumer('google'); if (!is_null($code)) { $token = $googleservice->requestaccesstoken($code); $google = json_decode($googleservice->request('https://www.googleapis.com/oauth2/v1/userinfo'), true); if(user::where('email', '=', $google['email'])->first()){ $user = user::where('email', '=', $google['email'])->first(); auth::login($user); return redirect('/'); } else { $user = new user(); $user->name = $google['name']; $user->email = $google['email']; $user->save(); auth::login($user); } } else { $url = $googleservice->getauthorizationuri(); return redirect((string)$url); } } }
Comments
Post a Comment