Skip to content

Conversation

@yamcodes
Copy link
Contributor

@yamcodes yamcodes commented Mar 21, 2025

Description

Implemented OpenAPI (swagger) token authentication for create, update, delete, and fetch operations in articles, profiles, and users.

Closes #131


PR Checklist

  • Read the Developer's Guide in CONTRIBUTING.md
  • Use a concise title to represent the changes introduced in this PR
  • Provide a detailed description of the changes introduced in this PR, and, if necessary, some screenshots
  • Reference an issue or discussion where the feature or changes have been previously discussed
  • Add a failing test that passes with the changes introduced in this PR, or explain why it's not feasible
  • Add documentation for the feature or changes introduced in this PR to the docs; you can run them with bun docs

Summary by CodeRabbit

  • New Features
    • Enhanced API security by requiring token-based authentication for key operations related to articles, profiles, and users.
  • Bug Fixes
    • Refined the feed endpoint description for improved clarity.

- Implemented token authentication for create, update, delete, and fetch operations in articles, profiles, and users.
- Updated API documentation to reflect the new security requirements for these endpoints.
@yamcodes yamcodes linked an issue Mar 21, 2025 that may be closed by this pull request
4 tasks
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 21, 2025

Walkthrough

The pull request removes a global security configuration block from the Swagger documentation setup in the application module and adds explicit security properties to the API endpoint configurations in the articles, profiles, and users plugins. In each of these plugins, the endpoints now include a security property specifying token-based authentication via an empty tokenAuth array. There are no changes to exported entities.

Changes

File(s) Change Summary
src/app.module.ts Removed the security configuration block from the Swagger documentation setup within the setupApp function.
src/articles/articles.plugin.ts
src/profiles/profiles.plugin.ts
src/users/users.plugin.ts
Added a new security property to the endpoint detail objects (e.g., for create, update, delete operations) specifying token-based authentication via an empty tokenAuth array.

Assessment against linked issues

Objective Addressed Explanation
All endpoints require authentication (#131)

Suggested reviewers

  • Hajbo

Poem

I hopped through code with a joyful heart,
Clearing out global blocks to set each part,
Endpoints now guard their precious gate,
With token auth keeping things up to date,
A rabbit’s cheer for changes that smartly articulate!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 57c8b05 and 4303929.

📒 Files selected for processing (1)
  • src/articles/articles.plugin.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/articles/articles.plugin.ts

🪧 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.

@yamcodes
Copy link
Contributor Author

I'm starting to think we should apply this security detail, along with our beforeHandle auth check (requireLogin) not to each route individually but using groups.

Less code to write. Thoughts? @Hajbo

@yamcodes
Copy link
Contributor Author

Before this change (notice the word "required" in the Swagger UI for routes that don't need it)
image

After this change
image

I think it's really useful

@yamcodes yamcodes marked this pull request as ready for review March 21, 2025 14:50
@yamcodes yamcodes requested a review from Hajbo March 21, 2025 14:50
@yamcodes yamcodes self-assigned this Mar 21, 2025
@yamcodes yamcodes changed the title feat: Add token authentication to article, profile, and user endpoints Swagger: Add token authentication to article, profile, and user endpoints Mar 21, 2025
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 (1)
src/articles/articles.plugin.ts (1)

75-80: Fix typo in endpoint summary

There's a typo in the endpoint summary - "Artifle Feed" should be "Article Feed".

-            summary: 'Artifle Feed',
+            summary: 'Article Feed',
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4de0208 and 57c8b05.

📒 Files selected for processing (4)
  • src/app.module.ts (0 hunks)
  • src/articles/articles.plugin.ts (4 hunks)
  • src/profiles/profiles.plugin.ts (3 hunks)
  • src/users/users.plugin.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • src/app.module.ts
🔇 Additional comments (8)
src/users/users.plugin.ts (2)

58-62: Well implemented security configuration for the Current User endpoint

The addition of the security property with tokenAuth to the API documentation aligns well with the endpoint's existing authentication through requireLogin. This enhances the documentation to accurately reflect that token authentication is required.


79-83: Well implemented security configuration for the Update User endpoint

The security property addition here matches the existing authentication middleware, properly documenting the token authentication requirement in the API documentation.

src/profiles/profiles.plugin.ts (3)

26-30: Proper security documentation for Profile endpoint

The added security configuration correctly reflects the authentication requirement already implemented through the requireLogin middleware.


46-50: Proper security documentation for Follow Profile endpoint

The security property matches the existing authentication check, ensuring API documentation accurately represents token requirements.


67-71: Proper security documentation for Unfollow Profile endpoint

The security configuration appropriately documents the authentication requirement consistent with the requireLogin middleware.

src/articles/articles.plugin.ts (3)

52-56: Well-implemented security for Create Article endpoint

The addition of the security property with tokenAuth aligns with the existing beforeHandle authentication requirement.


109-113: Proper security documentation for Update Article endpoint

The security property addition matches the existing authentication requirements.


129-133: Well-documented security for Delete Article endpoint

The security configuration appropriately reflects the token authentication requirement.

@Hajbo
Copy link
Collaborator

Hajbo commented Mar 22, 2025

I'm starting to think we should apply this security detail, along with our beforeHandle auth check (requireLogin) not to each route individually but using groups.

Less code to write. Thoughts? @Hajbo

We can definitely try grouping, I'm not sure how it would look like 🤔 But manually adding them also doesn't seem that painful, the security details can be extracted into a constant that we just use in each place to avoid writing a lot of duplicated code

I'm thinking something simple like this:

const swaggerRequireAuth = {security: [
              {
                tokenAuth: [],
              },
            ],
}


detail: {
            summary: 'Create Article',
            ...swaggerRequireAuth,
          },

@yamcodes yamcodes mentioned this pull request Mar 22, 2025
3 tasks
@yamcodes
Copy link
Contributor Author

#145 (comment)

Great points. Continued in #147

@yamcodes yamcodes merged commit 1c5abfb into main Mar 22, 2025
4 checks passed
@yamcodes yamcodes deleted the 131-all-endpoints-require-authentication branch March 22, 2025 06:43
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.

All endpoints require authentication

3 participants