Skip to content

Conversation

@klmhyeonwoo
Copy link
Collaborator

@klmhyeonwoo klmhyeonwoo commented Apr 20, 2025

목적

  • 소셜 로그인 시에 정상적인 토큰 값이 들어와도 401 에러를 뱉는 현상을 수정해요
  • 회원가입 로직 일부를 리팩토링해요

작업 내용

  • src/api/index.ts
    src/utils/constant.ts
    src/app/signin/index.tsx
    src/components/layout/header.tsx

    • 기존에는 토큰 이름을 FLOWBIT_ACT 이라고 명명했는데 너무 명시적으로 이름을 설정하는걸 방지하고자 ASCII 문자열로 변경했어요
  • src/hooks/useCheckEmail.ts

    • 뉴스레터 구독, 회원가입 쪽에서 이메일 인증 체크하는 부분이 있는데 이 부분을 공통적으로 사용하기 위한 커스텀 훅을 제작했어요
  • src/utils/constant.ts

    • 환경변수 일부를 설정했어요

필수 리뷰어

이슈 번호

Summary by CodeRabbit

  • New Features

    • Introduced a custom hook for email input management and validation.
    • Added a constants module with centralized keys and OAuth URLs.
  • Refactor

    • Replaced hardcoded access token and OAuth keys with imported constants across the app.
    • Unified and simplified social login handling and email validation logic in the sign-in flow.
  • Chores

    • Improved code consistency by centralizing authentication-related constants.
    • Updated pull request template formatting for better readability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 20, 2025

Walkthrough

The changes centralize authentication-related constants by introducing a new constants module and refactoring code throughout the application to use these constants instead of hardcoded strings. A custom React hook is added for email validation, replacing inline validation logic. Social login URLs are now managed via constants, and related click handlers are unified. The use of state management hooks is streamlined, and effect dependencies are updated for clarity. Overall, the update standardizes key usage, abstracts repeated logic, and improves maintainability.

Changes

File(s) Change Summary
src/utils/constant.ts Added new module exporting constants: ACCESS_TOKEN, EMAIL_PURPOSE, and OAUTH for centralized management of tokens, email purposes, and OAuth URLs.
src/hooks/useCheckEmail.ts Introduced a custom hook for managing email input state and validation, returning the email, its validity, and a change handler.
src/api/index.ts
src/components/layout/header.ts
Replaced hardcoded "FLOWBIT_ACT" localStorage key with imported ACCESS_TOKEN constant for token management.
src/app/oauth2/redierct/index.tsx Updated to use ACCESS_TOKEN constant for token storage; switched from useAtom to useSetAtom; adjusted effect dependencies and formatting.
src/app/signin/index.tsx Refactored to use useCheckEmail hook for email validation, unified social login handling with OAUTH constants, replaced local token key with ACCESS_TOKEN, and streamlined state management.
.github/pull_request_template.md Reformatted markdown headings to bold text style and improved spacing without changing content.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SignInComponent
    participant useCheckEmailHook
    participant ConstantsModule
    participant LocalStorage
    participant OAuthProvider

    User->>SignInComponent: Enter email / Click social login
    SignInComponent->>useCheckEmailHook: Validate email input
    useCheckEmailHook-->>SignInComponent: Return validity and value
    SignInComponent->>ConstantsModule: Get ACCESS_TOKEN / OAUTH URLs
    SignInComponent->>OAuthProvider: Redirect for social login
    OAuthProvider-->>SignInComponent: Return accessToken in URL
    SignInComponent->>LocalStorage: Store accessToken using ACCESS_TOKEN
Loading

Poem

In burrows deep, the code did sprawl,
With keys and tokens, hard to recall.
But now, constants guide our way,
And email checks make input play.
Social logins, neat and bright—
The rabbit hops with pure delight!
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this 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.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (2)
src/app/oauth2/redierct/index.tsx (1)

22-22: Consider adding dependencies to useEffect

The empty dependency array means this effect runs only once on mount, but it uses accessToken, setLogin, and navigate which should ideally be included in the dependency array.

-  }, []);
+  }, [accessToken, setLogin, navigate]);
src/app/signin/index.tsx (1)

88-88: Consider abstracting password validation

While using isValidEmail from the hook is good, the password validation (password.length > 5) is still hardcoded. Consider creating a similar hook or at least using a constant for minimum password length.

- state={isValidEmail && password.length > 5}
+ state={isValidEmail && password.length >= MIN_PASSWORD_LENGTH}

Where MIN_PASSWORD_LENGTH would be defined in your constants file:

// Add to src/utils/constant.ts
export const MIN_PASSWORD_LENGTH = 6;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06e57af and d386e7e.

📒 Files selected for processing (6)
  • src/api/index.ts (3 hunks)
  • src/app/oauth2/redierct/index.tsx (2 hunks)
  • src/app/signin/index.tsx (5 hunks)
  • src/components/layout/header.tsx (2 hunks)
  • src/hooks/useCheckEmail.ts (1 hunks)
  • src/utils/constant.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
src/api/index.ts (1)
src/utils/constant.ts (1)
  • ACCESS_TOKEN (16-16)
src/components/layout/header.tsx (1)
src/utils/constant.ts (1)
  • ACCESS_TOKEN (16-16)
src/hooks/useCheckEmail.ts (1)
src/utils/regex.ts (1)
  • EMAIL_REGEX (2-2)
src/app/oauth2/redierct/index.tsx (2)
src/store/user/index.ts (1)
  • loginState (3-3)
src/utils/constant.ts (1)
  • ACCESS_TOKEN (16-16)
src/app/signin/index.tsx (3)
src/store/user/index.ts (1)
  • loginState (3-3)
src/hooks/useCheckEmail.ts (1)
  • useCheckEmail (4-19)
src/utils/constant.ts (2)
  • ACCESS_TOKEN (16-16)
  • OAUTH (16-16)
🔇 Additional comments (19)
src/hooks/useCheckEmail.ts (1)

1-19: Well-structured custom hook for email validation.

This is a clean implementation of a custom hook that encapsulates email validation logic. The hook properly manages state, uses memoization with useCallback to prevent unnecessary re-renders, and provides a clear interface for components to use.

Some positive aspects of this implementation:

  • Good separation of concerns by extracting email validation logic into a reusable hook
  • Proper use of useState for managing both email value and validation state
  • Effective memoization of the change handler with useCallback
  • Clear typing for the event handler
  • Consistent validation using the imported EMAIL_REGEX
src/utils/constant.ts (1)

1-16: Good centralization of constants.

The creation of a central constants file is a good practice for maintaining consistent values across the application. The file is well-organized with appropriate comments for each section.

A few notes:

  • Using btoa() for the ACCESS_TOKEN adds a layer of obfuscation which is good for security
  • The as const assertion for EMAIL_PURPOSE ensures type safety
  • Environment variables are properly used for constructing OAuth URLs
src/components/layout/header.tsx (2)

21-21: Good use of centralized constant.

Importing the ACCESS_TOKEN constant from the central constants file aligns with the refactoring goal of the PR.


256-256: Consistent use of ACCESS_TOKEN constant.

Replacing the hardcoded string with the imported constant improves maintainability and consistency across the codebase.

src/api/index.ts (3)

1-1: Good use of centralized constant.

Importing the ACCESS_TOKEN constant from the central constants file aligns with the refactoring goal of the PR.


34-34: Consistent use of ACCESS_TOKEN constant in error handler.

Replacing the hardcoded string with the imported constant improves maintainability and consistency across the codebase.


44-44: Consistent use of ACCESS_TOKEN constant in request handler.

Replacing the hardcoded string with the imported constant improves maintainability and consistency across the codebase.

src/app/oauth2/redierct/index.tsx (4)

2-3: Good refactoring of imports and state management

The change to import ACCESS_TOKEN from constants and using useSetAtom instead of useAtom are both good improvements. Using useSetAtom is more efficient when you only need to update state without reading it.


12-12: Improved state management approach

Using useSetAtom instead of destructuring from useAtom is more efficient as this component only needs to set the login state, not read it.


16-16: Using centralized constant for token storage

Good replacement of hardcoded string with the ACCESS_TOKEN constant, improving maintainability.


19-20: More user-friendly error message

The error message is more clear for users when no access token is found.

src/app/signin/index.tsx (8)

15-17: Good architecture improvements with hooks and constants

The changes to use useSetAtom, centralized constants (ACCESS_TOKEN, OAUTH), and the custom useCheckEmail hook improve code organization and reusability.


21-22: Good refactoring of state management

Using useSetAtom for login state and delegating email validation to a custom hook simplifies the component and improves separation of concerns.


25-30: Using centralized constant for token handling

Good use of the ACCESS_TOKEN constant for consistency across the application.


32-34: Well-abstracted social login handler

Creating a dedicated function for social login redirection improves code maintainability and reduces duplication.


39-39: Consistent token constant usage

Good use of the ACCESS_TOKEN constant for token storage.


75-75: Using custom hook's handler improves code simplicity

Good refactoring to use the email change handler from the custom hook.


133-133: Good use of constants for social login URLs

Using the OAUTH.KAKAO constant with the unified handler improves maintainability.


143-143: Good use of constants for social login URLs

Using the OAUTH.GOOGLE constant with the unified handler improves maintainability.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (2)
.github/pull_request_template.md (2)

1-1: Use proper Markdown headings instead of emphasis

The template currently uses bold text (**제목**) for section titles, which triggers markdownlint’s MD036 rule and can reduce semantic clarity. Consider switching to heading syntax (e.g., ### 목적) to improve structure, accessibility, and consistency.

Also applies to: 5-5, 9-9, 13-13

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

1-1: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)


3-3: Remove or clarify standalone list markers

Standalone hyphens (-) render as empty list items, which can confuse contributors and linters. If these are placeholders, replace them with explicit instructions (e.g., <내용을 입력하세요>) or remove them to clean up the template.

Also applies to: 7-7, 15-15

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d386e7e and 5f8fc92.

📒 Files selected for processing (1)
  • .github/pull_request_template.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
.github/pull_request_template.md

1-1: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)


5-5: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)


9-9: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)


13-13: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)

Copy link
Member

@Cllaude99 Cllaude99 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!

@@ -0,0 +1,16 @@
/** 권한 관련 */
const ACCESS_TOKEN = btoa("FLOWBIT_ACT");
Copy link
Member

Choose a reason for hiding this comment

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

btoa를 사용하여 ASCII 문자열로 처리하신 점이 인상 깊었습니다. 해당 함수에 대해서도 처음으로 알게되었어요!

@klmhyeonwoo klmhyeonwoo merged commit 680ff4e into main Apr 21, 2025
2 checks passed
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.

4 participants