From 9632641702b33774c225eeb2ba626d0fa427ae28 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Tue, 14 Jan 2020 11:49:35 +0100 Subject: [PATCH] Better errors handling for user controller --- app/Http/Controllers/UserController.php | 10 +++++----- resources/js/views/Login.vue | 16 ++++++++-------- resources/js/views/Register.vue | 23 ++++++++++++++--------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 2274c7b5..fe0f4fb0 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -36,10 +36,10 @@ public function login(Request $request) $success['token'] = Auth::user()->createToken('MyApp')->accessToken; $success['name'] = Auth::user()->name; - return response()->json(['success' => $success], 200); + return response()->json(['message' => $success], 200); } - return response()->json(['error' => 'Unauthorised'], 401); + return response()->json(['message' => 'unauthorised'], 401); } @@ -53,7 +53,7 @@ public function logout() $accessToken = Auth::user()->token(); $accessToken->revoke(); - return response()->json(['success' => 'signed out']); + return response()->json(['message' => 'signed out']); } @@ -83,7 +83,7 @@ public function register(Request $request) $count = DB::table('users')->count(); if( $count > 0 ) { - return response()->json(['error' => __('already_one_user_registered')], 400); + return response()->json(['message' => __('errors.already_one_user_registered')], 400); } $validator = Validator::make($request->all(), [ @@ -103,7 +103,7 @@ public function register(Request $request) $success['token'] = $user->createToken('MyApp')->accessToken; $success['name'] = $user->name; - return response()->json(['success' => $success]); + return response()->json(['message' => $success]); } diff --git a/resources/js/views/Login.vue b/resources/js/views/Login.vue index 9841bafc..3cf991ed 100644 --- a/resources/js/views/Login.vue +++ b/resources/js/views/Login.vue @@ -9,14 +9,14 @@
{{ errors.email.toString() }}
+{{ validationErrors.email.toString() }}
{{ errors.password.toString() }}
+{{ validationErrors.password.toString() }}
{{ errors.name.toString() }}
+{{ validationErrors.name.toString() }}
{{ errors.email.toString() }}
+{{ validationErrors.email.toString() }}
{{ errors.password.toString() }}
+{{ validationErrors.password.toString() }}
{{ errors.passwordConfirmation.toString() }}
+{{ validationErrors.passwordConfirmation.toString() }}