authenticate(); $request->session()->regenerate(); return redirect()->intended(RouteServiceProvider::HOME); } /** * Handle an incoming api authentication request. * * @param \App\Http\Requests\Auth\LoginRequest $request * * @return \Illuminate\Http\Response */ public function apiStore(LoginRequest $request) { if (!Auth::attempt($request->only('email', 'password'))) { throw ValidationException::withMessages([ 'email' => ['The provided credentials are incorrect'] ]); } $user = User::where('email', $request->email)->first(); return response($user); } /** * Verifies user token. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response */ public function apiVerifyToken(Request $request) { $request->validate([ 'api_token' => 'required' ]); $user = User::where('api_token', $request->api_token)->first(); if (!$user) { throw ValidationException::withMessages([ 'token' => ['Invalid token'] ]); } return response($user); } /** * Destroy an authenticated session. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\RedirectResponse */ public function destroy(Request $request) { Auth::guard('web')->logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); return redirect('/'); } }