Skip to content

Change redirectToLogin to absolute path#30

Merged
OmerKat merged 6 commits intomainfrom
change-redirect-to-absolute-path
Sep 15, 2025
Merged

Change redirectToLogin to absolute path#30
OmerKat merged 6 commits intomainfrom
change-redirect-to-absolute-path

Conversation

@OmerKat
Copy link
Collaborator

@OmerKat OmerKat commented Sep 14, 2025

No description provided.

@claude
Copy link

claude bot commented Sep 14, 2025

Claude finished @OmerKat's task —— View job


Code Review for PR #30: Change redirectToLogin to absolute path

I've reviewed the changes in this PR. Here's my feedback:

Summary

This PR changes the redirectToLogin method in src/modules/auth.ts to use an absolute URL instead of a relative path by prepending options.serverUrl to the login URL (lines 57-59).

✅ Code Quality and Best Practices

  • The change follows the existing code style and patterns
  • Proper use of template literal for string concatenation
  • Maintains consistent formatting with the rest of the codebase

✅ Potential Bugs or Issues

  • Good: The change correctly handles URL encoding for the redirect URL parameter
  • Good: The serverUrl is already validated when creating the auth module
  • Good: Doesn't break the existing fallback to window.location.href when nextUrl is not provided

✅ Performance Considerations

  • No performance impact - this is a simple string concatenation that happens only during redirects

✅ Security Concerns

  • The change maintains proper URL encoding using encodeURIComponent() for the from_url parameter
  • No new security vulnerabilities introduced

❌ Test Coverage

Critical Issue: The existing tests in /tests/unit/auth.test.js are now broken by this change. Specifically:

  • Lines 151-152: Test expects /login?from_url=... but will now get https://api.base44.com/login?from_url=...
  • Lines 171-172: Same issue - test expects relative path but code now produces absolute path

Recommendation: Update the test assertions to expect the absolute URL format:

// Line 152 should be:
expect(mockLocation.href).toBe(
  `${serverUrl}/login?from_url=${encodeURIComponent(nextUrl)}`
);

// Line 172 should be:
expect(mockLocation.href).toBe(
  `${serverUrl}/login?from_url=${encodeURIComponent(currentUrl)}`
);

Additional Observations

  1. Missing PR Description: Consider adding a description explaining why this change was needed (e.g., was it to support cross-domain redirects, fix a bug, etc.)
  2. Custom Redirect Handler: The code includes support for options.onRedirectToLogin callback (lines 49-52) which allows custom redirect handling - this remains unaffected by the change

Recommendation

The code change itself is good and necessary for proper redirects when the application is hosted on a different domain than the auth server. However, the tests must be updated before merging to maintain test suite integrity.

@github-actions
Copy link

github-actions bot commented Sep 14, 2025

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/sdk@0.7.3-pr.30.196c2fc

Prefer not to change any import paths? Install using npm alias so your code still imports @base44/sdk:

npm i "@base44/sdk@npm:@base44-preview/sdk@0.7.3-pr.30.196c2fc"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "@base44/sdk": "npm:@base44-preview/sdk@0.7.3-pr.30.196c2fc"
  }
}

Preview published to npm registry — try new features instantly!

@claude
Copy link

claude bot commented Sep 14, 2025

Claude finished @OmerKat's task —— View job


Code Review for PR #30: Change redirectToLogin to absolute path

I've reviewed the updated changes in this PR. The author has addressed the test issues from my previous review.

Summary

This PR changes the redirectToLogin method in src/modules/auth.ts to use an absolute URL by prepending options.serverUrl to the login URL. The tests have been updated to match this change.

✅ Code Quality and Best Practices

  • The implementation follows the existing code style and patterns
  • Proper use of template literal for string concatenation
  • Maintains consistent formatting with the rest of the codebase
  • Clean and straightforward change

✅ Test Updates - Previous Feedback Addressed

Great work! The test assertions have been correctly updated to expect the absolute URL format:

  • Line 152: Now expects ${serverUrl}/login?from_url=...
  • Line 172: Now expects ${serverUrl}/login?from_url=...

The tests now properly validate that the redirect URL includes the full server URL as a prefix.

✅ Potential Bugs or Issues

  • No bugs identified
  • The serverUrl is validated when creating the auth module
  • Proper URL encoding is maintained with encodeURIComponent()
  • The fallback to window.location.href when nextUrl is not provided continues to work correctly

✅ Performance Considerations

  • No performance impact - this is a simple string concatenation that happens only during redirects
  • The change is minimal and focused

✅ Security Concerns

  • The change maintains proper URL encoding using encodeURIComponent() for the from_url parameter
  • No new security vulnerabilities introduced
  • The absolute URL helps prevent potential issues with relative path redirects in different deployment contexts

Additional Observations

  1. Missing PR Description: Consider adding a description explaining why this change was needed (e.g., to support cross-domain redirects, fix issues with different deployment contexts, etc.)
  2. The options.onRedirectToLogin callback functionality remains unaffected, which is good for backward compatibility

Recommendation

This PR is ready to merge. The code change is clean, tests have been properly updated, and no issues were found. The change improves the robustness of the redirect functionality by using absolute URLs.

@claude
Copy link

claude bot commented Sep 15, 2025

Claude finished @OmerKat's task —— View job


Code Review for PR #30: Change redirectToLogin to absolute path

I've reviewed all the changes in this PR. Here's my comprehensive feedback:

Summary

This PR makes two key changes:

  1. Primary change: Updates redirectToLogin method to use absolute URLs by prepending options.serverUrl to the login path
  2. Additional enhancement: Adds support for optional custom headers in the client configuration

✅ Code Quality and Best Practices

  • The implementation follows existing code patterns and conventions
  • Proper use of template literals for URL construction
  • Clean object spread syntax for merging optional headers
  • Maintains backward compatibility - the headers parameter is optional
  • Code style is consistent with the rest of the codebase

✅ Potential Bugs or Issues

  • No bugs identified in the implementation
  • The absolute URL change correctly includes both the from_url and app_id parameters
  • URL encoding is properly maintained with encodeURIComponent()
  • The optional headers feature correctly merges custom headers before setting the default X-App-Id header, allowing custom headers while preventing override of critical headers

✅ Performance Considerations

  • No performance impact - Both changes involve simple object spreading and string concatenation
  • Operations only occur during client initialization (headers) and redirect (URL construction)
  • No additional network calls or heavy computations introduced

✅ Security Concerns

  • URL encoding maintained: The from_url parameter continues to use encodeURIComponent() preventing URL injection
  • No security vulnerabilities introduced by the absolute URL change
  • Headers feature is secure: Custom headers cannot override the critical X-App-Id header due to the order of spreading
  • The absolute URL approach is actually more secure as it prevents potential issues with relative path manipulation in different deployment contexts

✅ Test Coverage

  • Tests properly updated: Both test cases in auth.test.js have been updated to expect the absolute URL format
  • Test assertions now correctly validate the full URL including serverUrl, from_url, and app_id parameters
  • All existing test scenarios remain covered

Additional Observations

  1. Missing PR Description: While the code changes are clear, adding a description would help explain:

    • Why the absolute URL change was needed (cross-domain support, deployment flexibility, etc.)
    • The rationale for adding custom headers support
  2. Headers Feature: The addition of optional headers (commit ad38cbd) is a useful enhancement that allows consumers to pass custom headers to all API requests. This maintains proper precedence where custom headers are applied first, then overridden by required headers like X-App-Id.

  3. Backward Compatibility: Both changes maintain full backward compatibility - existing code will continue to work without modifications.

Recommendation

This PR is ready to merge. The code is clean, tests are updated, and both features are implemented correctly without introducing any issues. The changes improve the SDK's flexibility for different deployment scenarios and custom header requirements.

@claude
Copy link

claude bot commented Sep 15, 2025

Claude finished @OmerKat's task —— View job


Code Review for PR #30: Change redirectToLogin to absolute path

I've completed my review of this PR. Here's my comprehensive feedback:

Summary

This PR makes two main changes:

  1. Primary change: Updates the redirectToLogin method to use absolute URLs by prepending options.serverUrl
  2. Additional feature: Adds support for optional custom headers in the client configuration
  3. New auth methods: Adds several authentication-related methods (register, OTP verification, password reset, etc.)

✅ Code Quality and Best Practices

  • Excellent code organization: The changes follow the existing patterns and conventions throughout the codebase
  • Type safety: Proper TypeScript types are used for all new parameters and methods
  • Consistent naming: Method names follow the camelCase convention used elsewhere
  • Clean implementation: The optional headers feature uses object spread syntax appropriately
  • Good API design: All new auth methods follow RESTful conventions and consistent parameter patterns

✅ Potential Bugs or Issues

  • No bugs identified in the implementation
  • Proper parameter handling: The app_id parameter is correctly added to the redirect URL
  • Backward compatibility maintained: The headers parameter is optional and won't break existing code
  • URL encoding preserved: The encodeURIComponent() function is correctly used for the from_url parameter
  • Null safety: Optional parameters in new auth methods properly handle null/undefined values

✅ Performance Considerations

  • No performance impact: The changes involve simple string concatenation and object spreading
  • No additional network calls: All changes are client-side operations
  • Minimal memory overhead: The optional headers are only stored if provided
  • Efficient implementation: No unnecessary computations or loops introduced

✅ Security Concerns

  • URL injection prevention: The use of encodeURIComponent() prevents URL injection attacks
  • Header precedence is secure: Custom headers are spread first, then overridden by critical headers like X-App-Id, preventing security-critical header tampering
  • No sensitive data exposure: The absolute URL approach doesn't expose any additional sensitive information
  • Authentication flow unchanged: The security model of the authentication process remains intact
  • Proper token handling: New auth methods don't expose tokens inappropriately

✅ Test Coverage

  • Tests properly updated: Both test cases in auth.test.js have been correctly updated to expect absolute URLs
  • Test assertions are comprehensive: Tests verify the full URL including serverUrl, from_url, and app_id parameters
  • All test scenarios remain covered: The existing test coverage is maintained

📝 Additional Observations

  1. Missing PR Description: While the code is self-explanatory, adding a PR description would help explain:

    • The motivation for using absolute URLs (cross-domain support, deployment flexibility)
    • Why the additional auth methods were added
    • The use case for custom headers
  2. Import Addition: The PR adds import { RegisterPayload } from "./auth.types"; but the RegisterPayload type isn't used in the visible code. The register method defines its payload inline instead. Consider either:

    • Using the imported type for consistency
    • Removing the unused import
  3. Method Duplication: There's a loginViaUsernamePassword method that appears to duplicate functionality with loginViaEmailPassword. Consider consolidating or clarifying the distinction between these methods.

  4. Comprehensive Auth Module Enhancement: The addition of registration, OTP verification, password reset, and user invitation methods significantly enhances the auth module's capabilities, making it a complete authentication solution.

✅ Recommendation

This PR is ready to merge. The implementation is solid, secure, and well-tested. The changes improve the SDK's flexibility for different deployment scenarios while maintaining backward compatibility.

@claude
Copy link

claude bot commented Sep 15, 2025

Claude finished @OmerKat's task —— View job


Code Review for PR #30: Change redirectToLogin to absolute path

I've reviewed all the changes in this PR. Here's my comprehensive feedback:

Summary

This PR makes three key changes:

  1. Primary change: Updates redirectToLogin method to use absolute URLs by prepending options.serverUrl
  2. Feature addition: Adds support for optional custom headers in the client configuration
  3. Auth enhancements: Adds multiple new authentication methods (register, OTP verification, password reset, etc.)

✅ Code Quality and Best Practices

  • Excellent code organization: All changes follow existing patterns and conventions
  • Type safety: Proper TypeScript types are used for all new parameters and methods
  • Consistent naming: Method names follow the established camelCase convention
  • Clean implementation: The optional headers feature uses object spread syntax appropriately
  • Good API design: New auth methods follow RESTful conventions with consistent parameter patterns

✅ Potential Bugs or Issues

  • No bugs identified in the implementation
  • Proper parameter handling: The app_id parameter is correctly added to the redirect URL
  • Backward compatibility maintained: The headers parameter is optional and won't break existing code
  • URL encoding preserved: The encodeURIComponent() function is correctly used for the from_url parameter
  • Null safety: Optional parameters in new auth methods handle null/undefined values properly

⚠️ Minor Issues

  1. Duplicate method: There's both loginViaEmailPassword and loginViaUsernamePassword methods that appear to have identical functionality (lines 131-163 and 205-213). Consider consolidating these or clarifying their distinct purposes.

✅ Performance Considerations

  • No performance impact: Changes involve simple string concatenation and object spreading
  • No additional network calls: All changes are client-side operations
  • Minimal memory overhead: Optional headers are only stored if provided
  • Efficient implementation: No unnecessary computations or loops introduced

✅ Security Concerns

  • URL injection prevention: Use of encodeURIComponent() prevents URL injection attacks
  • Header precedence is secure: Custom headers are spread first, then overridden by critical headers like X-App-Id, preventing tampering with security-critical headers
  • No sensitive data exposure: The absolute URL approach doesn't expose additional sensitive information
  • Authentication flow unchanged: The security model remains intact
  • Proper token handling: New auth methods don't expose tokens inappropriately

✅ Test Coverage

  • Tests properly updated: Both test cases in auth.test.js have been correctly updated to expect absolute URLs
  • Test assertions are comprehensive: Tests verify the full URL including serverUrl, from_url, and app_id parameters
  • All existing test scenarios covered: The test suite maintains its coverage

📝 Additional Observations

  1. Missing PR Description: While the code is self-explanatory, adding a PR description would help explain:

    • The motivation for using absolute URLs (cross-domain support, deployment flexibility)
    • Why the additional auth methods were added
    • The use case for custom headers
  2. Comprehensive Auth Module Enhancement: The addition of registration, OTP verification, password reset, and user invitation methods significantly enhances the auth module's capabilities, making it a complete authentication solution.

✅ Recommendation

This PR is ready to merge. The implementation is solid, secure, and well-tested. The changes improve the SDK's flexibility for different deployment scenarios while maintaining backward compatibility. The only minor suggestion is to consider consolidating the duplicate login methods.

return axios.post(`/apps/${appId}/auth/resend-otp`, { email });
},

loginViaUsernamePassword({
Copy link
Collaborator

Choose a reason for hiding this comment

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

we already have this as loginViaEmailPassword

@claude
Copy link

claude bot commented Sep 15, 2025

Claude finished @OmerKat's task —— View job


Code Review for PR #30: Change redirectToLogin to absolute path

I've completed my review of all the changes in this PR. Here's my comprehensive feedback:

Summary

This PR makes three key changes:

  1. Primary change: Updates redirectToLogin method to use absolute URLs by prepending options.serverUrl
  2. Feature addition: Adds support for optional custom headers in the client configuration
  3. Auth enhancements: Adds multiple new authentication methods (register, OTP verification, password reset, etc.)

✅ Code Quality and Best Practices

  • Excellent code organization: All changes follow existing patterns and conventions
  • Type safety: Proper TypeScript types are used for all new parameters and methods
  • Consistent naming: Method names follow the established camelCase convention
  • Clean implementation: The optional headers feature uses object spread syntax appropriately
  • Good API design: New auth methods follow RESTful conventions with consistent parameter patterns

✅ Potential Bugs or Issues

  • No bugs identified in the implementation
  • Proper parameter handling: The app_id parameter is correctly added to the redirect URL
  • Backward compatibility maintained: The headers parameter is optional and won't break existing code
  • URL encoding preserved: The encodeURIComponent() function is correctly used for the from_url parameter
  • Null safety: Optional parameters in new auth methods handle null/undefined values properly

ℹ️ Regarding the Duplicate Method Issue

The reviewer mentioned that loginViaUsernamePassword duplicates loginViaEmailPassword. However, after reviewing the current code:

  • I only found loginViaEmailPassword in the auth module (lines 131-163)
  • There is no loginViaUsernamePassword method in the current codebase
  • This issue may have been from an earlier commit that was already addressed

✅ Performance Considerations

  • No performance impact: Changes involve simple string concatenation and object spreading
  • No additional network calls: All changes are client-side operations
  • Minimal memory overhead: Optional headers are only stored if provided
  • Efficient implementation: No unnecessary computations or loops introduced

✅ Security Concerns

  • URL injection prevention: Use of encodeURIComponent() prevents URL injection attacks
  • Header precedence is secure: Custom headers are spread first, then overridden by critical headers like X-App-Id, preventing tampering with security-critical headers
  • No sensitive data exposure: The absolute URL approach doesn't expose additional sensitive information
  • Authentication flow unchanged: The security model remains intact
  • Proper token handling: New auth methods don't expose tokens inappropriately

✅ Test Coverage

  • Tests properly updated: Both test cases in auth.test.js have been correctly updated to expect absolute URLs
  • Test assertions are comprehensive: Tests verify the full URL including serverUrl, from_url, and app_id parameters
  • All existing test scenarios covered: The test suite maintains its coverage

📝 Additional Observations

  1. Missing PR Description: While the code is self-explanatory, adding a PR description would help explain:

    • The motivation for using absolute URLs (cross-domain support, deployment flexibility)
    • Why the additional auth methods were added
    • The use case for custom headers
  2. Comprehensive Auth Module Enhancement: The addition of registration, OTP verification, password reset, and user invitation methods significantly enhances the auth module's capabilities, making it a complete authentication solution.

✅ Recommendation

This PR is ready to merge. The implementation is solid, secure, and well-tested. The changes improve the SDK's flexibility for different deployment scenarios while maintaining backward compatibility.

@OmerKat OmerKat merged commit 9d3dc69 into main Sep 15, 2025
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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants