I have a User Model that has 2 Models that are always loaded with it via $with. On User Creation those two models are not created since the user has to create them after logging in and those being unavailable. To this point the Login works correctly, the user model is returned.
After the creation of those models that are always loaded with the user model, i have to login twice on postman since the first response only returns 204 No content suddenly and on the second login i get the correct user model.
I am using Laravel Sanctum and used Breeze for scaffolding. I Changed only the Authenticate middleware to return json objects after logging in like this:
public function handle(Request $request, Closure $next, string ...$guards): Response
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return response()->json([
'user' => Auth::user(),
], 200);
}
}
return $next($request);
}