From dbdae213e39b82ff8ee565df0774bd2f72f06140 Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Fri, 22 Aug 2025 03:11:57 +0000
Subject: (김준회) 로그인 에러 토스트 메시지 개선, 중공업 유저의 협력사 유저
 추가/수정시 전화번호 사용 반영
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/login/login-form.tsx | 54 ++++++++++++++++++++++++++++-------------
 1 file changed, 37 insertions(+), 17 deletions(-)

(limited to 'components/login/login-form.tsx')

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'),
-- 
cgit v1.2.3

