Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ユーザーデータの型変更 #66

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

Kubosaka
Copy link
Collaborator

@Kubosaka Kubosaka commented Nov 15, 2024

User description

概要

  • ローカルストレージに保存するユーザーデータの型を変更した
createdAt: "2024-11-15T16:10:31.615Z"
email: "[email protected]"
id: 1
name: "窪坂駿吾"
photoUrl: "https://lh3.googleusercontent.com/a/ACg8ocLv8SOdZXOMza6dNM18XC3wUCqTKoELlUSoXlqZy7RQ5uj-Fg=s96-c"
uid: "vKnTUDW968evYZq1zfTeOtmugxb2"
updatedAt: "2024-11-15T16:10:31.615Z"

PR Type

enhancement


Description

  • ユーザーデータの型をDBUserに変更し、JSON解析時に適用。
  • 各ページでのユーザーデータの取り扱いを更新し、プロパティ名を新しい型に合わせて修正。
  • サインアップロジックをFirebaseUserを使用するように変更。
  • 課題のソートロジックを調整。

Changes walkthrough 📝

Relevant files
Enhancement
page.tsx
Update user type to `DBUser` in camera page                           

app/src/app/camera/page.tsx

  • Changed user type to DBUser when parsing JSON.
  • Updated import statement for user type.
  • +2/-2     
    page.tsx
    Update user type and sorting logic in home page                   

    app/src/app/page.tsx

  • Changed user type to DBUser when parsing JSON.
  • Updated import statement for user type.
  • Adjusted sorting logic for assignments.
  • +5/-3     
    page.tsx
    Update user data handling in user page                                     

    app/src/app/user/page.tsx

  • Changed user type to DBUser.
  • Updated user data properties to match new type.
  • +4/-4     
    signInAndUp.ts
    Modify user storage and sign-up logic                                       

    app/src/lib/signInAndUp.ts

  • Changed user type to DBUser for storage.
  • Updated sign-up logic to use FirebaseUser.
  • +11/-13 

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Possible Bug
    userの型がUserからDBUserに変更されているが、signInOrUp関数内でのuserの生成方法が変更されていないため、firebaseUserの情報が失われる可能性がある。これにより、ユーザー情報が正しく保存されない可能性がある。

    Code Smell
    userData.photoURLuserData.photoUrlに変更されているが、他の部分での使用が一貫していない。これにより、将来的にバグが発生する可能性がある。

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Correct the property name to prevent potential undefined errors

    Ensure userData.photoUrl is correctly referenced to avoid undefined errors.

    app/src/app/user/page.tsx [54]

    -{userData.photoUrl ? (
    +{userData.photoURL ? (
    Suggestion importance[1-10]: 9

    Why: The suggestion correctly identifies a property name mismatch, which could lead to undefined errors. This change is critical for ensuring the code functions as intended.

    9
    Validate parsed user data to prevent runtime errors

    Ensure that userInfo is validated after parsing to avoid potential runtime errors.

    app/src/app/camera/page.tsx [110-111]

     const userInfo: User = JSON.parse(user);
    +if (!userInfo || !userInfo.uid) {
    +  console.error("Invalid user data.");
    +  return;
    +}
    Suggestion importance[1-10]: 7

    Why: The suggestion addresses a potential runtime error by validating the parsed user data, which is important for robustness.

    7
    Possible issue
    Handle fetch response status to manage errors effectively

    Check the response status of the fetch call to handle errors appropriately.

    app/src/app/page.tsx [112]

     const resAssignment = await fetch(
    +if (!resAssignment.ok) {
    +  throw new Error("Failed to fetch assignment data.");
    +}
    Suggestion importance[1-10]: 8

    Why: This suggestion improves error handling by checking the fetch response status, which is crucial for ensuring the application behaves correctly in case of API failures.

    8
    Validate API response to ensure user data is retrieved successfully

    Validate the response from the sign-up API to handle potential errors.

    app/src/lib/signInAndUp.ts [45-46]

     const resUser = await res.json();
    +if (!resUser) {
    +  throw new Error("Failed to retrieve user data after sign-up.");
    +}
    Suggestion importance[1-10]: 7

    Why: Validating the API response is a good practice to handle potential errors, ensuring that the application can gracefully handle unexpected situations.

    7

    Copy link
    Collaborator

    @hikahana hikahana left a comment

    Choose a reason for hiding this comment

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

    LGTM

    @hikahana hikahana merged commit ed400de into main Nov 15, 2024
    1 check passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants