- Why are you trying to create a “login“ route? You don’t “log in” to an API; you use a token to authorise the user.
- Why are you returning
successin the response body? That’s completely unnecessary. The client knows whether the request was “successful” or not based on the HTTP status code.
Cant login with tenant with api routes
Hello all, i am trying to interact with api routes for tenant on my laravel app. So i have installed tenancyforlaravel package. I have configured successfully web based routes and they work well, also api routes for central domain. But making api routes for tenant domain has become a good callange for me. So then i have created new file under /routes/tenant/api.php and i call this route on /routes/tenant.php require __DIR__.'/tenant/api.php';
// api.php `/routes/tenant/api.php`
Route::prefix('v1')->group(function () {
// Define your tenant-specific API routes here
Route::controller(RegisterController::class)->group(function()
{
Route::post('login', 'login');
});
});
And also i have created /app/Http/Controllers/API/Tenant/RegisterController.php with login function
public function login(Request $request)
{
// dd("Tenant Login");
if(Auth::attempt(['email' => $request->email, 'password' => $request->password]))
{
$user = Auth::user();
$success['token'] = $user->createToken('MyApp')->plainTextToken;
$success['name'] = $user->name;
return $this->sendResponse($success, '', 'User login successfully.');
} else {
return $this->sendError('Unauthorised.', ['error'=>'Unauthorised']);
}
}
Who should make login when i run thishttp://foo.localhost:8000/v1/login on postman. But return me
{
"success": false,
"message": "Unauthorised.",
"data": {
"error": "Unauthorised"
}
}
Does anyone how can i make this to work? I mean this should login the tenant profile, not the central profile
Please or to participate in this conversation.