forked from baron/baron-sso
네이버 계정 정합성 맞춤
This commit is contained in:
@@ -34,13 +34,53 @@ class AuthProxyService {
|
||||
}
|
||||
|
||||
static Exception _error(String key, String fallback, {String? detail}) {
|
||||
return Exception(
|
||||
tr(
|
||||
key,
|
||||
fallback: fallback,
|
||||
params: detail != null ? {'error': detail} : null,
|
||||
),
|
||||
);
|
||||
final params = detail != null ? {'error': detail} : null;
|
||||
var message = tr(key, fallback: fallback, params: params);
|
||||
if (message == key && fallback.isNotEmpty) {
|
||||
message = _interpolateFallback(fallback, params);
|
||||
}
|
||||
return Exception(message);
|
||||
}
|
||||
|
||||
static String _interpolateFallback(
|
||||
String fallback,
|
||||
Map<String, String>? params,
|
||||
) {
|
||||
var message = fallback;
|
||||
params?.forEach((key, value) {
|
||||
message = message.replaceAll('{{$key}}', value);
|
||||
});
|
||||
return message;
|
||||
}
|
||||
|
||||
static String _responseErrorDetail(http.Response response) {
|
||||
final body = response.body.trim();
|
||||
if (body.isEmpty) {
|
||||
return 'HTTP ${response.statusCode}';
|
||||
}
|
||||
try {
|
||||
final decoded = jsonDecode(body);
|
||||
if (decoded is Map<String, dynamic>) {
|
||||
final value = decoded['error'] ?? decoded['message'];
|
||||
if (value is String && value.trim().isNotEmpty) {
|
||||
return _formatUserPolicyError(value);
|
||||
}
|
||||
}
|
||||
} catch (_) {
|
||||
// Fall back to the raw response body.
|
||||
}
|
||||
return _formatUserPolicyError(body);
|
||||
}
|
||||
|
||||
static String _formatUserPolicyError(String message) {
|
||||
final normalized = message.toLowerCase();
|
||||
if (normalized.contains(
|
||||
'internal email domain cannot be assigned to personal tenant',
|
||||
) ||
|
||||
normalized.contains('내부 도메인 사용자는 개인 소속으로 생성하거나 변경할 수 없습니다')) {
|
||||
return '내부 도메인 사용자는 개인 소속으로 생성하거나 변경할 수 없습니다. 대표소속을 회사 또는 조직 소속으로 지정해 주세요.';
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
static http.Client _createClient({bool withCredentials = false}) {
|
||||
@@ -735,8 +775,8 @@ class AuthProxyService {
|
||||
if (response.statusCode != 200) {
|
||||
throw _error(
|
||||
'err.userfront.auth_proxy.user_create',
|
||||
'Failed to create the user: {{error}}',
|
||||
detail: response.body,
|
||||
'사용자 생성 실패: {{error}}',
|
||||
detail: _responseErrorDetail(response),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -844,8 +884,8 @@ class AuthProxyService {
|
||||
if (response.statusCode != 200) {
|
||||
throw _error(
|
||||
'err.userfront.auth_proxy.user_update',
|
||||
'Failed to update the user: {{error}}',
|
||||
detail: response.body,
|
||||
'사용자 수정 실패: {{error}}',
|
||||
detail: _responseErrorDetail(response),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user