@prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ class AuthController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ protected $_config; public function __construct() { $this->middleware('admin')->except(['show','create']); $this->_config = request('_config'); } public function create(Request $request) { $request->validate([ 'email' => 'required|email', 'password' => 'required' ]); $credentials['email'] = $request->input('email'); $credentials['password'] = $request->input('password'); if ($token = $this->guard()->attempt(request(['email', 'password']))) { return $this->respondWithToken($token); } return response()->json(['error' => 'Unauthorized'], 401); } /** * Get the token array structure. * * @param string $token * * @return \Illuminate\Http\JsonResponse */ protected function respondWithToken($token) { return response()->json([ 'access_token' => $token, 'token_type' => 'bearer', 'expires_in' => auth('api')->factory()->getTTL() * 60, 'admin_id' => auth()->guard('admin-api')->user()->id, 'admin_email' => auth()->guard('admin-api')->user()->email ]); } /** * Get the guard to be used during authentication. * * @return \Illuminate\Contracts\Auth\Guard */ public function guard() { return auth()->guard('admin-api'); } /** * Refresh a token. * * @return \Illuminate\Http\JsonResponse */ public function refresh() { return $this->respondWithToken($this->guard()->refresh()); } /** * Get the authenticated User * * @return \Illuminate\Http\JsonResponse */ public function me() { return response()->json($this->guard()->user()); } public function destroy($id) { $this->guard()->logout(); return response()->json(['message' => 'Successfully logged out']); } }