Skip to content

Conversation

tusharpandey13
Copy link
Contributor

@tusharpandey13 tusharpandey13 commented Sep 5, 2025

Improves type safety by replacing unsafe as any cast with proper TypeScript type assertion in the withPageAuthRequired higher-order component.

Fixes: #2288

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

🔍 RCA

The withPageAuthRequired HOC used an unsafe as any type assertion for prop spreading, which bypassed TypeScript's type checking and indicated potential type compatibility issues between generic constraints and component props.

📋 Changes

This change improves type safety without affecting runtime behavior. The HOC now uses proper TypeScript type assertions that maintain compile-time type checking while preserving the same functionality.

Changed src/client/helpers/with-page-auth-required.tsx: Replace unsafe as any cast with type-safe React.ComponentProps<typeof Component> assertion

📎 References

🎯 Testing

Automated:
All existing tests continue to pass (302/302 test suite). No new tests required as this is a type-level improvement without functional changes.

Manual:

  1. Verify TypeScript compilation succeeds with npx tsc --noEmit
  2. Build SDK with pnpm build
  3. Test integration in sample app using yalc publish and yalc add @auth0/nextjs-auth0
  4. Confirm withPageAuthRequired HOC functions identically to previous behavior

@tusharpandey13 tusharpandey13 requested a review from a team as a code owner September 5, 2025 12:25
@codecov-commenter
Copy link

codecov-commenter commented Sep 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.37%. Comparing base (fe1f5e7) to head (5d935bd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2305      +/-   ##
==========================================
+ Coverage   85.34%   85.37%   +0.03%     
==========================================
  Files          26       26              
  Lines        2613     2619       +6     
  Branches      481      482       +1     
==========================================
+ Hits         2230     2236       +6     
  Misses        377      377              
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tusharpandey13
Copy link
Contributor Author

@claude

Copy link

github-actions bot commented Sep 5, 2025

Claude finished @tusharpandey13's task —— View job


Code Review Complete ✅

Todo List:

  • Read diff to understand changes
  • Read project copilot instructions (not found, continuing)
  • Analyze the modified file
  • Create pending review
  • Add review comments for any issues
  • Submit final review assessment

Summary

Completed code review of PR #2305. The change successfully improves type safety by replacing unsafe as any with a more specific type assertion. Identified one area for potential further improvement regarding prop type conflicts, but overall this is a solid enhancement to the codebase's type safety.


Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Overall Assessment

✅ This PR improves type safety by removing the unsafe as any cast

The change successfully replaces the problematic as any with a more specific type assertion. While there's still a minor type safety concern with potential prop conflicts, this is a significant improvement over the previous implementation. The change maintains the same runtime behavior while providing better TypeScript checking.

tusharpandey13 and others added 2 commits September 10, 2025 16:49
…wing type

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
….ComponentProps<typeof Component>, 'user'> here
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.

withPageAuthRequired regression on prop type inference when using InferGetServerSidePropsType<typeof getServerSideProps>
3 participants