I have two laravel projects
Bac4laravel v.8InfraProjectlaravel v.9
I want them to communicate using the Laravel Sanctum API. I want the InfraProject to access some data in the Bac4 project and vice versa.
The Problem
When InfraProject is trying to access the Bac4 using a token, InfraProject is being silly.
InfraProject is using its own database to verify the token from the Bac4.
Mind you that the Token is in the database of Bac4.
I can't seem to find the problem why the InfraProject is using it's own database to verify the token from another database.
I came to this conclusion that the InfraProject is accessing its own database is because i have tried to use a login API
Bac4
Route::post('/login', function (Request $request) {
$credentials = $request->validate([
'email' => 'required|email',
'password' => 'required',
]);
if (!Auth::attempt($credentials)) {
return response()->json(['message' => 'Invalid credentials'], 401);
}
$user = Auth::user();
$token = $user->createToken('API Token')->plainTextToken;
return response()->json([
'user' => $user,
'token' => $token,
]);
});
InfraProject The credentials are definitely in the bac4 database.
$response = Http::post('http://bac4.test/api/login', [
'email' => 'ba****[email protected]',
'password' => '******',
]);
$token = $response->json('token');
dd($token, $response);
but when i use a credential from the InfraProject's database. It produced a Token.
What i have tried
I have tried to remove the middleware auth:sanctum which i have declared in Bac4.
Route::get('prs', [PrController::class, 'index']);
But the InfraProject is, again, using its own database to access the prs table.
I ensured that both projects has
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class in the kernel in api array.
I also ensure that all affected models has a $connection specified.
ChatGpt can't figure the root cause of this, so this is my last chance.
I hope that you can help me.