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

✨ Use profile image from oauth provider #1330

Merged
merged 1 commit into from
Sep 7, 2024
Merged

✨ Use profile image from oauth provider #1330

merged 1 commit into from
Sep 7, 2024

Conversation

lukevella
Copy link
Owner

@lukevella lukevella commented Sep 7, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a CurrentUserAvatar component to display the currently logged-in user's avatar.
    • Added user image support in the authentication process, enhancing user profile representation.
  • Bug Fixes

    • Removed redundant user properties from the session interface, streamlining user data management.
  • Documentation

    • Updated import paths for components to improve clarity and organization.
  • Chores

    • Added a new dependency for avatar components from the Radix UI library.
    • Implemented new path mappings for easier module resolution in the project.

Copy link

vercel bot commented Sep 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 7, 2024 3:50pm
landing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 7, 2024 3:50pm

Copy link
Contributor

coderabbitai bot commented Sep 7, 2024

Walkthrough

The changes involve modifications to user avatar handling, session management, and component organization within the application. Key updates include the introduction of a new CurrentUserAvatar component, adjustments to session properties to include user images, and a restructuring of import statements for better clarity. Additionally, new dependencies have been added, and path mappings in TypeScript configuration have been updated to simplify module resolution.

Changes

File(s) Change Summary
apps/web/declarations/next-auth.d.ts Modified Session interface to inherit user properties from DefaultSession["user"].
apps/web/src/app/[locale]/(admin)/sidebar.tsx Updated import for CurrentUserAvatar from @/components/user to @/components/current-user-avatar.
apps/web/src/components/current-user-avatar.tsx Introduced CurrentUserAvatar component to display user avatars with fallback options.
apps/web/src/components/settings/profile-settings.tsx Replaced UserAvatar with CurrentUserAvatar, simplifying avatar handling.
apps/web/src/components/user-dropdown.tsx Updated import for CurrentUserAvatar and changed size prop to a class-based approach.
apps/web/src/components/user-provider.tsx Added image property to userSchema and adjusted user context handling.
apps/web/src/components/user.tsx Removed the implementation of CurrentUserAvatar, indicating a shift in avatar management.
apps/web/src/utils/auth.ts Enhanced session handling by adding image property to user session data.
packages/ui/package.json Added @radix-ui/react-avatar as a new dependency for avatar components.
packages/ui/src/avatar.tsx Introduced components for rendering avatars using Radix UI primitives.
packages/ui/src/command.tsx Changed import of Icon from an external library to a local module.
packages/ui/tsconfig.json Added new path mappings for easier module resolution.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant UserProvider
    participant Auth

    User->>App: Log in
    App->>Auth: Authenticate user
    Auth-->>App: Return user data with image
    App->>UserProvider: Set user context
    UserProvider-->>App: Provide user data
    App->>User: Display CurrentUserAvatar
Loading

🐰 In the meadow, I hop with glee,
New avatars for all to see!
With images bright and paths so clear,
Our user joy is finally here!
So let’s celebrate with a joyful cheer! 🎉


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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: 1

Outside diff range, codebase verification and nitpick comments (2)
packages/ui/tsconfig.json (1)

5-9: Incorrect path mappings in tsconfig.json.

The path mappings specified in the tsconfig.json file do not correspond to existing directories or files in the project. Please review and correct the following path mappings:

  • "@/utils": Ensure that src/lib/utils.ts exists.
  • "@/components/*": Ensure that the relevant directories or files exist under src.
  • "@/ui/*": Ensure that the relevant directories or files exist under src.
Analysis chain

Verify new path mappings for correctness.

The new path mappings introduced in the tsconfig.json are intended to simplify imports and improve maintainability. However, it's crucial to verify that the specified paths correctly map to existing directories and files in the project structure.

Run the following script to verify the existence of the directories and files specified in the path mappings:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of directories and files specified in the path mappings.

# Test: Check if the paths exist in the filesystem. Expect: Directories and files should exist.
if [ -d "src/lib" ] && [ -f "src/lib/utils.ts" ] && [ -d "src" ]; then
  echo "All specified paths exist."
else
  echo "Some paths do not exist. Please check the path mappings."
fi

Length of output: 143


Script:

#!/bin/bash
# Description: Verify the existence of directories and files specified in the path mappings for components and ui.

# Check if the directories for components and ui exist
components_exist=false
ui_exist=false

if [ -d "src" ]; then
  # Check for any files or directories under src for components
  if [ "$(find src -type d -name '*components*' -o -type f -name '*components*')" ]; then
    components_exist=true
  fi

  # Check for any files or directories under src for ui
  if [ "$(find src -type d -name '*ui*' -o -type f -name '*ui*')" ]; then
    ui_exist=true
  fi
fi

echo "Components path exists: $components_exist"
echo "UI path exists: $ui_exist"

Length of output: 180

apps/web/src/components/user.tsx (1)

Line range hint 1-1: Component Removal Noted: CurrentUserAvatar.

The removal of CurrentUserAvatar indicates a significant change in avatar handling. Ensure that this change is well-documented and that the new avatar handling logic is integrated elsewhere in the application.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between be21634 and 4f5fc2b.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (12)
  • apps/web/declarations/next-auth.d.ts (1 hunks)
  • apps/web/src/app/[locale]/(admin)/sidebar.tsx (1 hunks)
  • apps/web/src/components/current-user-avatar.tsx (1 hunks)
  • apps/web/src/components/settings/profile-settings.tsx (3 hunks)
  • apps/web/src/components/user-dropdown.tsx (2 hunks)
  • apps/web/src/components/user-provider.tsx (2 hunks)
  • apps/web/src/components/user.tsx (1 hunks)
  • apps/web/src/utils/auth.ts (4 hunks)
  • packages/ui/package.json (1 hunks)
  • packages/ui/src/avatar.tsx (1 hunks)
  • packages/ui/src/command.tsx (1 hunks)
  • packages/ui/tsconfig.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • apps/web/src/app/[locale]/(admin)/sidebar.tsx
Additional comments not posted (14)
apps/web/declarations/next-auth.d.ts (1)

18-18: Approve the changes to the Session interface.

The modification to extend DefaultSession["user"] in the Session interface is a positive change, reducing redundancy and aligning with default definitions. Ensure that all necessary user properties are still correctly accessible and integrated throughout the application.

Run the following script to verify the integration of the Session interface changes with the rest of the application:

Verification successful

Integration of Session Interface Changes Verified

The extension of the Session interface to include properties from DefaultSession["user"] is well-integrated across the application. The properties are accessed correctly in various components and server-side functions. Ensure that any custom properties added to the Session interface are also handled appropriately throughout the codebase.

  • Key files where Session is used:
    • apps/web/src/utils/auth.ts
    • apps/web/src/pages/_app.tsx
    • apps/web/src/components/user-provider.tsx
    • apps/web/src/pages/api/stripe/portal.ts
    • apps/web/src/app/[locale]/auth/login/login-page.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of the `Session` interface changes with the rest of the application.

# Test: Search for usage of the `Session` interface. Expect: Proper handling of properties.
rg --type typescript -A 5 $'Session'

Length of output: 70


Script:

#!/bin/bash
# Description: Verify the integration of the `Session` interface changes with the rest of the application.

# Test: Search for usage of the `Session` interface. Expect: Proper handling of properties.
rg --type ts -A 5 $'Session'

Length of output: 20761

packages/ui/package.json (1)

16-16: Approved addition of new dependency.

The addition of @radix-ui/react-avatar is correctly implemented with the appropriate version. Ensure compatibility with existing dependencies and assess the impact on the package size and performance.

Verification successful

Dependency Compatibility Verified

The addition of @radix-ui/react-avatar version ^1.1.0 is consistent with other @radix-ui dependencies in the packages/ui/package.json file. No immediate compatibility issues are evident with the existing dependencies. Ensure to monitor for any updates or known issues related to these dependencies.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential conflicts with new dependency.

# Test: List all dependencies and their versions.
cat package.json | jq '.dependencies'

Length of output: 248


Script:

#!/bin/bash
# Description: Check the package.json in the packages/ui directory for the new dependency.

# Test: List all dependencies and their versions in the packages/ui/package.json file.
cat packages/ui/package.json | jq '.dependencies'

Length of output: 794

apps/web/src/components/user.tsx (1)

Line range hint 9-28: Review of UserAvatar Component.

The UserAvatar component appears correctly implemented with dynamic styling based on the user's name and size. Ensure that this component integrates seamlessly with the new avatar handling logic introduced elsewhere.

packages/ui/src/avatar.tsx (1)

1-50: Approved New Avatar Components.

The new components Avatar, AvatarImage, and AvatarFallback are correctly implemented using React patterns and the @radix-ui/react-avatar dependency. Ensure these components are properly integrated and documented within the UI package.

Verification successful

Integration of Avatar Components Verified

The new components Avatar, AvatarImage, and AvatarFallback are successfully integrated into the UI package, as evidenced by their usage in the CurrentUserAvatar component. This confirms the review comment's approval.

  • The components are used in the CurrentUserAvatar component, indicating proper integration.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify integration of new avatar components within the UI package.

# Test: Search for usage of new avatar components in the application.
rg --type tsx 'Avatar|AvatarImage|AvatarFallback'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify integration of new avatar components within the UI package.

# Find all .tsx files and search for usage of new avatar components.
fd --extension tsx --exec rg 'Avatar|AvatarImage|AvatarFallback' {}

Length of output: 3645

apps/web/src/components/settings/profile-settings.tsx (2)

12-12: Approved import changes.

The new imports (CurrentUserAvatar, Trans, useUser) are appropriate for the updated component functionality.


42-42: Component update approved.

The use of CurrentUserAvatar with a fixed class name simplifies the component logic and potentially improves performance by reducing unnecessary re-renders.

apps/web/src/components/user-provider.tsx (2)

24-24: Schema update approved.

The addition of the image property as a nullable string is a sensible enhancement to the user schema, allowing for the inclusion of user avatars in the UI.


80-83: Provider updates approved.

The direct use of the isGuest variable and the inclusion of the image property in the user object streamline the component and enhance its functionality by supporting user avatars.

packages/ui/src/command.tsx (1)

10-10: Approved import change.

The local sourcing of the Icon component from ./icon instead of @rallly/ui/icon reduces external dependencies and potentially simplifies maintenance.

apps/web/src/components/user-dropdown.tsx (2)

60-60: Verify the new class usage for CurrentUserAvatar.

The size prop has been replaced with className="size-6". Ensure that the class size-6 is defined in the CSS and correctly applies the intended styles.


29-29: Verify the new import path for CurrentUserAvatar.

The import path for CurrentUserAvatar has been updated. Please ensure that the component is correctly exported from @/components/current-user-avatar and that this path is correctly configured in the TypeScript path mappings.

Verification successful

Import Path Verified for CurrentUserAvatar.

The CurrentUserAvatar component is correctly exported from apps/web/src/components/current-user-avatar.tsx as a named export. The import path update is valid and correctly reflects the component's location. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new import path for `CurrentUserAvatar`.

# Test: Search for the export statement of `CurrentUserAvatar` in the new path. Expect: Export statement found.
rg --type ts -A 5 $'export { CurrentUserAvatar }' '@/components/current-user-avatar'

Length of output: 203


Script:

#!/bin/bash
# Step 1: Locate the file corresponding to the alias "@/components/current-user-avatar"
fd 'current-user-avatar.tsx' --type f

# Step 2: Verify the export statement for `CurrentUserAvatar` in the located file
# This will be executed after identifying the correct file path from Step 1

Length of output: 85


Script:

#!/bin/bash
# Verify the export statement for `CurrentUserAvatar` in the located file
rg 'export { CurrentUserAvatar }' apps/web/src/components/current-user-avatar.tsx

Length of output: 203


Script:

#!/bin/bash
# Verify the export statement for `CurrentUserAvatar` in the located file with corrected regex
rg 'export \{ CurrentUserAvatar \}' apps/web/src/components/current-user-avatar.tsx

Length of output: 85


Script:

#!/bin/bash
# Search for any export statements in the file to identify how `CurrentUserAvatar` is exported
rg 'export ' apps/web/src/components/current-user-avatar.tsx

Length of output: 140

apps/web/src/utils/auth.ts (3)

294-294: Verify the handling of the image property in the session.

The image property has been added to the session user object in the session callback. Ensure that this property is correctly handled in the session and does not introduce inconsistencies.


283-283: Verify the handling of the image property in the JWT.

The image property has been added to the JWT in the jwt callback. Ensure that this property is correctly handled and does not introduce security or privacy issues.

Verification successful

Verified: The image property is correctly handled in the JWT and session.

The image property is assigned to token.picture and then used to set session.user.image, ensuring the image URL is available in the session. This implementation appears correct and does not introduce any immediate security or privacy issues. However, ensure that the image URL is properly sanitized and does not contain sensitive information.

  • token.picture = user.image; is correctly used to set session.user.image.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the handling of the `image` property in the JWT.

# Test: Search for the JWT handling code to ensure the `image` property is correctly managed. Expect: Proper handling found.
rg --type ts -A 5 $'token.picture' '@/utils'

Length of output: 89


Script:

#!/bin/bash
# Locate the auth.ts file within the apps/web/src/utils directory.
fd 'auth.ts' --exec rg --type ts -A 5 'token.picture' {}

Length of output: 344


57-57: Verify the handling of the image property in the user object.

The image property has been added to the user object in the authorize method. Ensure that the database schema includes this property and that it is correctly handled in the user object throughout the authentication process.

Verification successful

The image property is correctly supported in the database schema.

The image property is defined as an optional string in the schema.prisma file, confirming its support in the database schema. Ensure that the application logic appropriately handles cases where this field might be null.

  • Location: packages/database/prisma/schema.prisma
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the handling of the `image` property in the user object.

# Test: Search for the database schema definition of the `image` property. Expect: Schema definition found.
rg --type sql -A 5 $'image' '@/migrations'

Length of output: 92


Script:

#!/bin/bash
# Locate SQL or migration files in the repository
fd --type f --extension sql --extension prisma

# Once located, search for the `image` property within those files
rg --type sql --type prisma -A 5 'image'

Length of output: 4708


Script:

#!/bin/bash
# Search for the `image` property within the `schema.prisma` file
rg 'image' packages/database/prisma/schema.prisma -A 5

Length of output: 312

@lukevella lukevella merged commit 364bb8b into main Sep 7, 2024
7 checks passed
@lukevella lukevella deleted the profile-image branch September 7, 2024 15:57
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.

1 participant