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

feat: implement logout action and save activities #152

Merged
merged 1 commit into from
Sep 16, 2024
Merged

Conversation

andostronaut
Copy link
Member

@andostronaut andostronaut commented Sep 16, 2024

This is an automated pull request for branch develop

Summary by CodeRabbit

  • New Features

    • Introduced user activity logging for login, registration, and logout actions.
    • Added a new API route to retrieve device type information.
    • Implemented a logout functionality in the UserSettings component.
  • Configuration

    • Added a new environment variable APP_URL for enhanced application configuration.
  • Bug Fixes

    • Improved error handling for user activity logging and logout processes.

Copy link

coderabbitai bot commented Sep 16, 2024

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on enhancing user authentication and activity tracking. A new environment variable APP_URL is added to support application configuration. The authentication actions are updated to log user activities for login, registration, and logout events. Additionally, a new API route is created to retrieve device type information, and the dashboard layout is modified to utilize the new logout functionality.

Changes

File Change Summary
.env.example, env.d.ts, next.config.mjs Added the environment variable APP_URL=http://localhost:3000 to .env.example and declared it in env.d.ts. Updated next.config.mjs to set APP_URL from the environment variable.
app/(auth)/actions.ts Modified login and register functions to include user activity logging and changed redirection paths. Added a new logout function to handle user logout and activity logging.
app/(dashboard)/actions.ts Introduced a new asynchronous function saveActivity to log user activities in the Supabase database.
app/api/device/route.ts Created a new API route to handle GET requests for device type information, returning a JSON response with the device details.
components/layouts/dashboard-layout.tsx Updated the UserSettings component to utilize the new logout function from authentication actions, enhancing the logout process.

Possibly related PRs

  • feat: init supabase #133: The addition of the SUPABASE_URL and SUPABASE_ANON_KEY environment variables in the .env.example file is related to the main PR's addition of the APP_URL variable, as both enhance the application's configuration options for different environments.
  • feat: toggle pwd and pwd confirm visibility #140: Changes in app/(auth)/actions.ts where the logout function is defined and utilized are relevant since the main PR also modifies the authentication actions in the same file.
  • feat: handle user account register #141: The implementation of the register function in app/(auth)/actions.ts is related to the main PR as it also involves changes to the authentication actions in the same file.
  • feat: create login action #142: The modifications to the login function in app/(auth)/actions.ts are relevant as they are part of the same file where the main PR's changes occur.
  • feat: get authenticated user and show user connected in header #143: The changes to the login function's redirection behavior in app/(auth)/actions.ts are relevant as they also affect the same file modified in the main PR.
  • feat: impl activities page and table #151: The implementation of the activities page and table may utilize the new environment variable APP_URL for routing or API calls, linking it to the main PR's changes.

🐇 In the code we hop and play,
New paths and logs light our way.
With APP_URL set just right,
Our app will shine, a joyful sight!
Logout and log, we track with glee,
Hopping forward, come code with me! 🌟


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 generate interesting stats about this repository and render them as a table.
    -- @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

@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 (1)
app/api/device/route.ts (1)

10-14: Log the error for debugging purposes.

Consider logging the error using console.error or a logging library before returning the error response. This will help with debugging if an error occurs.

Apply this diff to log the error:

  } catch (error) {
+   console.error('Failed to retrieve device type:', error)
    return new Response(JSON.stringify({ error: 'Failed to retrieve device type' }), {
      status: 500
    })
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 73f1acf and 53395a2.

Files selected for processing (7)
  • .env.example (1 hunks)
  • app/(auth)/actions.ts (4 hunks)
  • app/(dashboard)/actions.ts (1 hunks)
  • app/api/device/route.ts (1 hunks)
  • components/layouts/dashboard-layout.tsx (3 hunks)
  • env.d.ts (1 hunks)
  • next.config.mjs (1 hunks)
Additional comments not posted (10)
.env.example (1)

1-3: LGTM!

Adding the APP_URL environment variable to the .env.example file is a good practice. It provides a clear example for developers to set up their local environment.

The value http://localhost:3000 is a typical URL for running the application in a local development environment.

next.config.mjs (1)

4-4: LGTM!

The addition of the APP_URL environment variable to the env object is a good practice for configuring environment-specific values in Next.js applications. This change enhances the configurability and flexibility of the application by allowing it to adapt to different environments.

The value of APP_URL is correctly set to process.env.APP_URL, which ensures that the application can access the environment-specific value at runtime.

This change does not introduce any apparent issues or bugs and may improve the maintainability of the codebase by centralizing the configuration of environment variables.

env.d.ts (1)

4-4: LGTM!

The addition of the APP_URL property to the ProcessEnv interface is a valid TypeScript declaration. It enhances the configuration options available for the application by providing a centralized way to access the application's URL from anywhere in the codebase.

The change is consistent with the existing property declarations and does not introduce any breaking changes or compatibility issues.

app/(dashboard)/actions.ts (1)

8-35: The function implementation looks good overall.

The function correctly handles the optional user information, uses the Supabase client to interact with the database, and returns the inserted data or an error message. With the suggested improvements for error handling and input validation, this function will be more robust and reliable.

app/(auth)/actions.ts (3)

Line range hint 12-31: LGTM!

The changes to the login function look good:

  • The addition of activity logging through the saveActivity function is a nice enhancement to track user actions.
  • The updated redirection to /dashboard/reports after a successful login improves the user experience.
  • Error handling for the sign-in process is correctly implemented.

Line range hint 33-66: LGTM!

The changes to the register function look good:

  • The addition of activity logging through the saveActivity function is a nice enhancement to track user actions.
  • The function correctly checks for existing usernames and handles error scenarios during the sign-up process.
  • The redirection to /auth after a successful sign-up is appropriate.

68-85: Great job implementing the logout functionality!

The new logout function looks solid:

  • It correctly handles the sign-out process by logging the activity, clearing cookies, and redirecting to the home page.
  • Error handling is implemented for both the sign-out process and the activity logging, ensuring that any issues are captured and returned.
  • The function follows best practices for implementing a secure logout mechanism.
components/layouts/dashboard-layout.tsx (3)

30-31: LGTM!

The logout function is correctly imported from the authentication actions.


173-173: LGTM!

The handleLogout function is correctly defined, and it calls the logout function.


195-195: LGTM!

The onClick event of the logout button is correctly set to handleLogout.

app/api/device/route.ts Show resolved Hide resolved
app/(dashboard)/actions.ts Show resolved Hide resolved
app/(dashboard)/actions.ts Show resolved Hide resolved
@andostronaut andostronaut merged commit 9ec6141 into main Sep 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant