Skip to content

Conversation

@minkyung5x5
Copy link
Contributor

@minkyung5x5 minkyung5x5 commented Nov 13, 2024

πŸ”– Issue Ticket

Ticket

✍️ Description

둜그인/νšŒμ›κ°€μž… API μš”μ²­μ‹œμ—λ§Œ return 값에 헀더값 λ°›μ•„μ˜€λŠ” κ²ƒμœΌλ‘œ μˆ˜μ •

βœ… Checklist

PR

  • Branch Convention 확인

    feat/ 피쳐, fix/ 버그 μˆ˜μ •, refactor/ κ°œμ„ 

  • Base Branch 확인
  • μ μ ˆν•œ Label μ§€μ •
  • Assignee 및 Reviewer μ§€μ •

Test

  • 둜컬 μž‘λ™ 확인

Summary by CodeRabbit

  • μ‹ κ·œ κΈ°λŠ₯

    • μ‚¬μš©μž 둜그인 및 νšŒμ›κ°€μž… API μš”μ²­μ— νƒ€μž„μ•„μ›ƒ 및 인증 ν”Œλž˜κ·Έ μΆ”κ°€.
    • 인증 μš”μ²­μ— λŒ€ν•œ 응닡 ꡬ쑰 κ°œμ„ , 데이터와 헀더λ₯Ό ν•¨κ»˜ λ°˜ν™˜ κ°€λŠ₯.
  • 버그 μˆ˜μ •

    • 였λ₯˜ 처리 둜직 μœ μ§€ 및 κ°œμ„ , νŠΉμ • 였λ₯˜μ— λŒ€ν•œ 처리 κ°•ν™”.

@coderabbitai
Copy link

coderabbitai bot commented Nov 13, 2024

Walkthrough

이 λ³€κ²½ 사항은 src/_apis/auth/auth-apis.tsx 파일의 signupUser 및 loginUser ν•¨μˆ˜μ— λŒ€ν•œ μˆ˜μ •μœΌλ‘œ, 두 ν•¨μˆ˜ λͺ¨λ‘ fetchApi ν˜ΈμΆœμ— 5000λ°€λ¦¬μ΄ˆμ˜ νƒ€μž„μ•„μ›ƒ κ°’κ³Ό true둜 μ„€μ •λœ λΆ€μšΈ ν”Œλž˜κ·Έλ₯Ό μΆ”κ°€ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. src/utils/api.ts νŒŒμΌμ—μ„œλŠ” fetchApi ν•¨μˆ˜μ— isAuth λ§€κ°œλ³€μˆ˜λ₯Ό μΆ”κ°€ν•˜μ—¬ 인증된 μš”μ²­μ„ μ²˜λ¦¬ν•˜λŠ” 방식을 κ°œμ„ ν–ˆμŠ΅λ‹ˆλ‹€. λ˜ν•œ, ApiError 클래슀의 μƒμ„±μžμ— λŒ€ν•œ νƒ€μž… 주석이 μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

Changes

파일 경둜 λ³€κ²½ μš”μ•½
src/_apis/auth/auth-apis.tsx signupUser 및 loginUser ν•¨μˆ˜μ—μ„œ fetchApi ν˜ΈμΆœμ— νƒ€μž„μ•„μ›ƒ 및 인증 ν”Œλž˜κ·Έ μΆ”κ°€.
src/utils/api.ts fetchApi ν•¨μˆ˜μ— isAuth λ§€κ°œλ³€μˆ˜ μΆ”κ°€, ApiError 클래슀의 μƒμ„±μžμ— νƒ€μž… 주석 μΆ”κ°€.

Possibly related PRs

  • Feat/101/login signup apiΒ #106: 이 PR은 src/_apis/auth/auth-apis.tsx 파일의 signupUser 및 loginUser ν•¨μˆ˜λ„ μˆ˜μ •ν•˜μ—¬ API μš”μ²­ 및 응닡 ꡬ쑰 μ²˜λ¦¬μ™€ 관련이 μžˆμŠ΅λ‹ˆλ‹€.

Suggested labels

fix, pages

Suggested reviewers

  • yulrang
  • Rangbyeolang

🐰 λ³€ν™”μ˜ λ°”λžŒμ΄ λΆˆμ–΄μ™€
둜그인과 κ°€μž…μ΄ 더 μ‰¬μ›Œμ‘Œλ„€
νƒ€μž„μ•„μ›ƒκ³Ό 인증이 ν•¨κ»˜ ν•˜λ‹ˆ
API의 길이 λ”μš± λ°μ•„μ‘Œμ–΄!
ν•¨κ»˜ 뛰어놀며 κΈ°λ»ν•˜μž,
μ½”λ“œμ˜ μˆ²μ—μ„œ 즐거운 ν•˜λ£¨! 🌟

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

πŸ”§ eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/_apis/auth/auth-apis.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't determine the plugin "react-hooks" uniquely.

  • /node_modules/eslint-plugin-react-hooks/index.js (loaded in ".eslintrc.js")
  • /node_modules/eslint-config-next/node_modules/eslint-plugin-react-hooks/index.js (loaded in ".eslintrc.js Β» eslint-config-next/core-web-vitals Β» /node_modules/eslint-config-next/index.js Β» plugin:react-hooks/recommended")

Please remove the "plugins" setting from either config or remove either plugin installation.

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (2)
src/_apis/auth/auth-apis.tsx (1)

5-16: νƒ€μž„μ•„μ›ƒ 값을 μƒμˆ˜λ‘œ λΆ„λ¦¬ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€

ν•˜λ“œμ½”λ”©λœ νƒ€μž„μ•„μ›ƒ κ°’(5000)을 μƒμˆ˜λ‘œ λΆ„λ¦¬ν•˜μ—¬ μž¬μ‚¬μš©μ„±κ³Ό μœ μ§€λ³΄μˆ˜μ„±μ„ ν–₯μƒμ‹œν‚€λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

λ‹€μŒκ³Ό 같이 μˆ˜μ •ν•˜λŠ” 것을 μ œμ•ˆν•©λ‹ˆλ‹€:

+const AUTH_REQUEST_TIMEOUT = 5000;

 export function signupUser(data: SignupRequest): Promise<{ data: SignupResponse }> {
   return fetchApi<{ data: SignupResponse; headers: Headers }>(
     '/auths/signup',
     {
       method: 'POST',
       headers: {
         'Content-Type': 'application/json',
       },
       body: JSON.stringify(data),
     },
-    5000,
+    AUTH_REQUEST_TIMEOUT,
     true,
   ).then((response) => {
src/utils/api.ts (1)

22-22: λ§€κ°œλ³€μˆ˜ 이름을 더 λͺ…ν™•ν•˜κ²Œ κ°œμ„ ν•˜λ©΄ μ’‹κ² μŠ΅λ‹ˆλ‹€.

isAuthλ³΄λ‹€λŠ” includeHeaders λ˜λŠ” returnAuthHeaders와 같이 λ§€κ°œλ³€μˆ˜μ˜ λͺ©μ μ„ 더 λͺ…ν™•ν•˜κ²Œ ν‘œν˜„ν•˜λŠ” 이름을 μ‚¬μš©ν•˜λŠ” 것이 μ’‹κ² μŠ΅λ‹ˆλ‹€.

- isAuth = false,
+ includeHeaders = false,
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 7c0c126 and 5b7611f.

πŸ“’ Files selected for processing (2)
  • src/_apis/auth/auth-apis.tsx (1 hunks)
  • src/utils/api.ts (2 hunks)
πŸ”‡ Additional comments (2)
src/utils/api.ts (2)

Line range hint 6-9: νƒ€μž… 주석 μΆ”κ°€κ°€ μ μ ˆν•©λ‹ˆλ‹€!

detail λ§€κ°œλ³€μˆ˜μ— λŒ€ν•œ νƒ€μž… 주석이 클래슀 속성과 μΌμΉ˜ν•˜λ©°, νƒ€μž… μ•ˆμ •μ„±μ„ ν–₯μƒμ‹œν‚΅λ‹ˆλ‹€.


Line range hint 1-65: 인증 κ΄€λ ¨ λ³€κ²½μ‚¬ν•­μ˜ 영ν–₯도λ₯Ό ν™•μΈν•΄μ£Όμ„Έμš”.

이 변경사항이 κΈ°μ‘΄ 인증 흐름에 λ―ΈμΉ˜λŠ” 영ν–₯을 ν™•μΈν•˜κΈ° μœ„ν•΄ λ‹€μŒ 사항듀을 κ²€μ¦ν•΄μ£Όμ„Έμš”:

βœ… Verification successful

인증 κ΄€λ ¨ 변경사항이 κΈ°μ‘΄ 인증 흐름에 영ν–₯을 λ―ΈμΉ˜μ§€ μ•ŠμŒμ„ ν™•μΈν–ˆμŠ΅λ‹ˆλ‹€.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 인증 κ΄€λ ¨ API 호좜 νŒ¨ν„΄ 확인
echo "Checking auth API call patterns..."
rg -l "fetchApi.*isAuth.*true" src/

# μ—λŸ¬ 처리 νŒ¨ν„΄ 확인
echo "Checking error handling patterns..."
ast-grep --pattern 'catch (error) { 
  $$$
  ApiError 
  $$$
}'

Length of output: 263

Comment on lines +5 to +16
return fetchApi<{ data: SignupResponse; headers: Headers }>(
'/auths/signup',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
},
body: JSON.stringify(data),
}).then((response) => {
5000,
true,
).then((response) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

μ—λŸ¬ 처리 둜직이 ν•„μš”ν•©λ‹ˆλ‹€

둜그인과 νšŒμ›κ°€μž… ν•¨μˆ˜μ—μ„œ λ„€νŠΈμ›Œν¬ 였λ₯˜λ‚˜ μ„œλ²„ 였λ₯˜μ— λŒ€ν•œ μ²˜λ¦¬κ°€ λˆ„λ½λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. μ‚¬μš©μžμ—κ²Œ μ μ ˆν•œ μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό μ œκ³΅ν•˜κΈ° μœ„ν•΄ μ—λŸ¬ 처리λ₯Ό μΆ”κ°€ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

λ‹€μŒκ³Ό 같은 μ—λŸ¬ 처리 λ‘œμ§μ„ μΆ”κ°€ν•˜λŠ” 것을 μ œμ•ˆν•©λ‹ˆλ‹€:

 export function signupUser(data: SignupRequest): Promise<{ data: SignupResponse }> {
   return fetchApi<{ data: SignupResponse; headers: Headers }>(
     '/auths/signup',
     {
       method: 'POST',
       headers: {
         'Content-Type': 'application/json',
       },
       body: JSON.stringify(data),
     },
     5000,
     true,
-  ).then((response) => {
+  ).then((response) => {
     const token = response.headers.get('Authorization');
+    if (!token) {
+      throw new Error('인증 토큰을 λ°›μ§€ λͺ»ν–ˆμŠ΅λ‹ˆλ‹€');
+    }
     return { data: { token } };
+  }).catch((error) => {
+    if (error.status === 409) {
+      throw new Error('이미 μ‘΄μž¬ν•˜λŠ” μ‚¬μš©μžμž…λ‹ˆλ‹€');
+    }
+    throw new Error('νšŒμ›κ°€μž… 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€');
   });
 }

Also applies to: 23-34


πŸ› οΈ Refactor suggestion

쀑볡 μ½”λ“œλ₯Ό μœ ν‹Έλ¦¬ν‹° ν•¨μˆ˜λ‘œ λΆ„λ¦¬ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€

signupUser와 loginUser ν•¨μˆ˜μ˜ ꡬ쑰가 맀우 μœ μ‚¬ν•©λ‹ˆλ‹€. μ½”λ“œ 쀑볡을 쀄이고 μœ μ§€λ³΄μˆ˜μ„±μ„ 높이기 μœ„ν•΄ 곡톡 λ‘œμ§μ„ λ³„λ„μ˜ μœ ν‹Έλ¦¬ν‹° ν•¨μˆ˜λ‘œ λΆ„λ¦¬ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

λ‹€μŒκ³Ό 같이 λ¦¬νŒ©ν† λ§ν•˜λŠ” 것을 μ œμ•ˆν•©λ‹ˆλ‹€:

+const handleAuthRequest = async <T>(
+  endpoint: string,
+  data: any
+): Promise<{ data: T }> => {
+  const response = await fetchApi<{ data: T; headers: Headers }>(
+    endpoint,
+    {
+      method: 'POST',
+      headers: {
+        'Content-Type': 'application/json',
+      },
+      body: JSON.stringify(data),
+    },
+    5000,
+    true
+  );
+  
+  const token = response.headers.get('Authorization');
+  if (!token) {
+    throw new Error('인증 토큰을 λ°›μ§€ λͺ»ν–ˆμŠ΅λ‹ˆλ‹€');
+  }
+  return { data: { token } as T };
+};

 export function signupUser(data: SignupRequest): Promise<{ data: SignupResponse }> {
-  return fetchApi<{ data: SignupResponse; headers: Headers }>(
-    '/auths/signup',
-    {
-      method: 'POST',
-      headers: {
-        'Content-Type': 'application/json',
-      },
-      body: JSON.stringify(data),
-    },
-    5000,
-    true,
-  ).then((response) => {
-    const token = response.headers.get('Authorization');
-    return { data: { token } };
-  });
+  return handleAuthRequest<SignupResponse>('/auths/signup', data);
 }

 export function loginUser(data: LoginRequest): Promise<{ data: LoginResponse }> {
-  return fetchApi<{ data: LoginResponse; headers: Headers }>(
-    '/auths/login',
-    {
-      method: 'POST',
-      headers: {
-        'Content-Type': 'application/json',
-      },
-      body: JSON.stringify(data),
-    },
-    5000,
-    true,
-  ).then((response) => {
-    const token = response.headers.get('Authorization');
-    return { data: { token } };
-  });
+  return handleAuthRequest<LoginResponse>('/auths/login', data);
 }

Also applies to: 23-34

Comment on lines +54 to +55
if (isAuth) return { data, headers: response.headers } as T;
return { data } as T;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

λ°˜ν™˜ νƒ€μž… μ²˜λ¦¬μ— λŒ€ν•œ κ°œμ„ μ΄ ν•„μš”ν•©λ‹ˆλ‹€.

λ‹€μŒκ³Ό 같은 λ¬Έμ œμ λ“€μ΄ μžˆμŠ΅λ‹ˆλ‹€:

  1. 쑰건뢀 λ°˜ν™˜ νƒ€μž…μœΌλ‘œ 인해 νƒ€μž… μ•ˆμ „μ„±μ΄ μ €ν•˜λ  수 μžˆμŠ΅λ‹ˆλ‹€.
  2. 인증에 ν•„μš”ν•œ ν•„μˆ˜ ν—€λ”μ˜ 쑴재 μ—¬λΆ€λ₯Ό ν™•μΈν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

λ‹€μŒκ³Ό 같은 κ°œμ„ μ„ μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

interface AuthResponse<T> {
  data: T;
  headers: Headers;
}

interface DataResponse<T> {
  data: T;
}

export async function fetchApi<T>(
  url: string,
  options: RequestInit = {},
  timeout = 5000,
  includeHeaders = false,
): Promise<AuthResponse<T> | DataResponse<T>> {
  // ... existing code ...
  
  if (includeHeaders) {
    const requiredHeaders = ['authorization', 'content-type'];
    const missingHeaders = requiredHeaders.filter(
      header => !response.headers.has(header)
    );
    
    if (missingHeaders.length > 0) {
      throw new ApiError(
        500,
        `Missing required headers: ${missingHeaders.join(', ')}`
      );
    }
    
    return { data, headers: response.headers } as AuthResponse<T>;
  }
  
  return { data } as DataResponse<T>;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants