Closed Rasool-deldar closed 3 years ago
I want to use Laravel Synctum for multiple authentication ( spa ) when I use the sanctum drive.
These are my codes
// auth.php 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'admin' => [ 'driver' => 'sanctum', 'provider' => 'admins', ], 'api' => [ 'driver' => 'token', 'provider' => 'users', 'hash' => false, ], ],
// controller public function verification(Request $request) { // check verification user $checkVerification = $this->checkVerification($request); // get user & login $admin = $this->adminRepository->firstWithSelect([ 'mobile' => $checkVerification->mobile, ], ['id']); Auth::guard('admin')->loginUsingId($admin, true); // auth()->guard('admin')->loginUsingId($admin, true); $this->userVerificationRepository->update([ 'code_verification' => $request->post('code'), 'guard_type' => 'admin', ], [ 'code_verification' => 0, ]); $request->session()->regenerate(); // return data return response()->notification('successful'); }
// api.php Route::middleware('auth:sanctum')->get('/user', function (Request $request) { return $request->user(); });
But when I put the drive on my sync, it gives the following error
"message": "Method Illuminate\\Auth\\RequestGuard::loginUsingId does not exist.", "exception": "BadMethodCallException", "file": "C:\\Dev\\Web\\Laragon\\www\\digikala\\digikala-api\\vendor\\laravel\\framework\\src\\Illuminate\\Macroable\\Traits\\Macroable.php", "line": 103, "trace": [ { "file": "C:\\Dev\\Web\\Laragon\\www\\digikala\\digikala-api\\Modules\\Admin\\Http\\Controllers\\AuthController.php", "line": 101, "function": "__call", "class": "Illuminate\\Auth\\RequestGuard", "type": "->" }, { "file": "C:\\Dev\\Web\\Laragon\\www\\digikala\\digikala-api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php", "line": 54, "function": "verification", "class": "Modules\\Admin\\Http\\Controllers\\AuthController", "type": "->" }, { "file": "C:\\Dev\\Web\\Laragon\\www\\digikala\\digikala-api\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php", "line": 45, "function": "callAction", "class": "Illuminate\\Routing\\Controller", "type": "->" }, ]
When I drive the session, it gives the following error.
{ "message": "Unauthenticated." }
This method indeed doesn't exists on the Sanctum guard. If you need this you'd probably want a session guard instead.
Description:
I want to use Laravel Synctum for multiple authentication ( spa ) when I use the sanctum drive.
These are my codes
But when I put the drive on my sync, it gives the following error
When I drive the session, it gives the following error.