- 백엔드 TenantController: GET /api/tenant/check?subdomain=xxx (메타 DB 강제 라우팅 + CompanyResolver 로 존재 여부 반환) - frontend/lib/tenant/subdomain.ts: 호스트 파싱 + 예약어(solution/www/admin 등) 제외 - TenantGuard 클라이언트 컴포넌트: layout.tsx 에서 wrap, sessionStorage 로 같은 서브도메인 재체크 방지 - /tenant-not-found 페이지: v5 solid+glow 스타일 등록되지 않은 서브도메인 접속 시 즉시 /tenant-not-found 로 리다이렉트.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.erp.tenant;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 테넌트 서브도메인 검증용 공개 API.
|
||||
* 로그인 전 프론트 TenantGuard 가 "회사 존재 여부" 체크에 사용.
|
||||
*
|
||||
* GET /api/tenant/check?subdomain=qnc
|
||||
* → { "subdomain": "qnc", "exists": true }
|
||||
*
|
||||
* SecurityConfig 에서 /api/** 전부 permitAll 이라 별도 설정 불필요.
|
||||
* 메타 DB 로 강제 라우팅해야 테넌트 DB context 가 섞이지 않음.
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/tenant")
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class TenantController {
|
||||
|
||||
private final CompanyResolver companyResolver;
|
||||
|
||||
@GetMapping("/check")
|
||||
public Map<String, Object> check(@RequestParam("subdomain") String subdomain) {
|
||||
DbContextHolder.setMeta();
|
||||
try {
|
||||
String dbName = companyResolver.resolveDbName(subdomain);
|
||||
Map<String, Object> res = new LinkedHashMap<>();
|
||||
res.put("subdomain", subdomain);
|
||||
res.put("exists", dbName != null);
|
||||
return res;
|
||||
} finally {
|
||||
DbContextHolder.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user