fix : 테넌트 없는 회원 처리 및 테넌트 등록시 해당 테넌트 디폴트값 설정

This commit is contained in:
2025-08-14 20:19:51 +09:00
parent e9d1e42359
commit 9935bba84e
4 changed files with 37 additions and 21 deletions

View File

@@ -49,16 +49,21 @@ public function handle(Request $request, Closure $next)
$user = $accessToken->tokenable;
if ($user) {
// 기본 테넌트(여러개 소속시 우선순위)
$tenantId = $user->tenant?->tenant_id ?? $user->userTenants->first()?->tenant_id;
// 기본 테넌트(여러개 소속시 활성화 테넌트)
$tenantId = $user->userTenants
->where('is_default', 1)
->first()?->tenant_id
?? $user->userTenants->first()?->tenant_id;
$tenantId = $tenantId ?? 0;
// tenant_id 설정
$request->attributes->set('tenant_id', $tenantId);
$request->attributes->set('api_user', $user->id);
// ApiKeyMiddleware 등에서
app()->instance('api_user', $user->id);
app()->instance('tenant_id', $tenantId);
// user_id 설정
$request->attributes->set('api_user', $user->id);
app()->instance('api_user', $user->id);
}
}
}
@@ -75,8 +80,8 @@ public function handle(Request $request, Closure $next)
if (!in_array($currentRoute, $allowWithoutAuth)) {
// 인증정보(api_user, tenant_id) 없으면 튕김
if (!app()->bound('api_user') || !app()->bound('tenant_id')) {
throw new AuthenticationException('회원정보 또는 테넌트 정보 없음');
if (!app()->bound('api_user')) {
throw new AuthenticationException('회원정보 정보 없음');
}
}