summaryrefslogtreecommitdiff
path: root/components/login
diff options
context:
space:
mode:
Diffstat (limited to 'components/login')
-rw-r--r--components/login/login-form.tsx54
1 files changed, 37 insertions, 17 deletions
diff --git a/components/login/login-form.tsx b/components/login/login-form.tsx
index f8ba21d9..7453edb6 100644
--- a/components/login/login-form.tsx
+++ b/components/login/login-form.tsx
@@ -9,7 +9,7 @@ import { useToast } from "@/hooks/use-toast";
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem } from "@/components/ui/dropdown-menu"
import { useTranslation } from '@/i18n/client'
import { useRouter, useParams, usePathname, useSearchParams } from 'next/navigation';
-import { signIn, getSession } from 'next-auth/react';
+import { signIn } from 'next-auth/react';
import { buttonVariants } from "@/components/ui/button"
import Link from "next/link"
import Image from 'next/image';
@@ -23,10 +23,7 @@ import { requestPasswordResetAction } from "@/lib/users/auth/partners-auth";
type LoginMethod = 'username' | 'sgips';
-export function LoginForm({
- className,
- ...props
-}: React.ComponentProps<"div">) {
+export function LoginForm() {
const params = useParams() || {};
const pathname = usePathname() || '';
const router = useRouter();
@@ -75,6 +72,32 @@ export function LoginForm({
const currentLanguageText = i18n.language === 'ko' ? t('languages.korean') : t('languages.english');
+ // 세분화된 에러 메시지 처리 함수
+ const getErrorMessage = (error: { errorCode?: string; message?: string }, provider: 'email' | 'sgips') => {
+ const errorCode = error.errorCode;
+
+ if (!errorCode) {
+ return error.message || t('authenticationFailed');
+ }
+
+ switch (errorCode) {
+ case 'INVALID_CREDENTIALS':
+ return provider === 'sgips' ? t('sgipsInvalidCredentials') : t('invalidCredentials');
+ case 'ACCOUNT_LOCKED':
+ return t('accountLocked');
+ case 'ACCOUNT_DEACTIVATED':
+ return t('accountDeactivated');
+ case 'RATE_LIMITED':
+ return t('rateLimited');
+ case 'VENDOR_NOT_FOUND':
+ return t('vendorNotFound');
+ case 'SYSTEM_ERROR':
+ return t('systemError');
+ default:
+ return error.message || t('authenticationFailed');
+ }
+ };
+
const goToVendorRegistration = () => {
router.push(`/${lng}/partners/repository`);
};
@@ -120,7 +143,10 @@ export function LoginForm({
const result = await response.json();
if (!response.ok) {
- throw new Error(result.error || t('authenticationFailed'));
+ // 세분화된 에러 메시지 처리
+ const error = new Error(result.error || t('authenticationFailed')) as Error & { errorCode?: string };
+ error.errorCode = result.errorCode;
+ throw error;
}
return result;
@@ -216,7 +242,7 @@ export function LoginForm({
const callbackUrl = new URL(callbackUrlParam);
const relativeUrl = callbackUrl.pathname + callbackUrl.search;
router.push(relativeUrl);
- } catch (e) {
+ } catch {
router.push(callbackUrlParam);
}
} else {
@@ -297,13 +323,10 @@ export function LoginForm({
description: t('sendingCodeToPhone'),
});
}
- } catch (error: any) {
+ } catch (error: unknown) {
console.error('Username login error:', error);
- let errorMessage = t('invalidCredentials');
- if (error.message) {
- errorMessage = error.message;
- }
+ const errorMessage = getErrorMessage(error as { errorCode?: string; message?: string }, 'email');
toast({
title: t('errorTitle'),
@@ -356,13 +379,10 @@ export function LoginForm({
description: t('sendingCodeToSgipsPhone'),
});
}
- } catch (error: any) {
+ } catch (error: unknown) {
console.error('S-Gips login error:', error);
- let errorMessage = t('sgipsLoginFailed');
- if (error.message) {
- errorMessage = error.message;
- }
+ const errorMessage = getErrorMessage(error as { errorCode?: string; message?: string }, 'sgips');
toast({
title: t('errorTitle'),