Skip to content

Commit

Permalink
fix debug the token
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Jun 26, 2024
1 parent 928747d commit 892131c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/Http/Controllers/Api/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace NexaMerchant\Apis\Http\Controllers\Api;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

class Controller extends BaseController
{
use DispatchesJobs, ValidatesRequests;
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
38 changes: 17 additions & 21 deletions src/Http/Controllers/Api/V1/Shop/Customer/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,10 @@ public function getCode(Request $request)

//send email to user



return response(['message' => trans('Apis::app.shop.customer.code.sent')]);


return response(['message' => trans('Apis::app.shop.customer.code.sent'), 'code'=>$code]);

}

Expand All @@ -297,6 +298,7 @@ public function LoginWithCode(Request $request)
$request->validate([
'email' => 'required|email',
'code' => 'required',
'device_name' => 'required',
]);

$customer = $this->customerRepository->findOneByField('email', $request->email);
Expand All @@ -309,28 +311,22 @@ public function LoginWithCode(Request $request)
if($code!= $request->code){
return response(['message' => 'Invalid code'], 404);
}
if (! EnsureFrontendRequestsAreStateful::fromFrontend($request)) {
$request->validate([
'device_name' => 'required',
]);

$customer = $this->customerRepository->where('email', $request->email)->first();
//var_dump(EnsureFrontendRequestsAreStateful::fromFrontend($request));exit;

/**
* Preventing multiple token creation.
*/
$customer->tokens()->delete();
$customer = $this->customerRepository->where('email', $request->email)->first();

/**
* Event passed to prepare cart after login.
*/
Event::dispatch('customer.after.login', $request->get('email'));
//var_dump($customer);exit;

return response([
'data' => new CustomerResource($customer),
'message' => trans('Apis::app.shop.customer.accounts.logged-in-success'),
'token' => $customer->createToken($request->device_name, ['role:customer'])->plainTextToken,
]);
}
/**
* Event passed to prepare cart after login.
*/
Event::dispatch('customer.after.login', $request->get('email'));

return response([
'data' => new CustomerResource($customer),
'message' => trans('Apis::app.shop.customer.accounts.logged-in-success'),
'token' => $customer->createToken($request->device_name, ['role:customer'])->plainTextToken,
]);
}
}
5 changes: 5 additions & 0 deletions src/Http/Controllers/Api/V1/V1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
namespace NexaMerchant\Apis\Http\Controllers\Api\V1;

use NexaMerchant\Apis\Http\Controllers\Api\Controller;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

class V1Controller extends Controller
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

0 comments on commit 892131c

Please sign in to comment.