Skip to content

Conversation

@yogeshchoudhary147
Copy link
Contributor

@yogeshchoudhary147 yogeshchoudhary147 commented Jan 24, 2026

Description

This PR refactors the provideAuth0 function to return EnvironmentProviders instead of Provider[], enforcing type safety at compile-time and preventing incorrect usage in component providers.

Fixes #664

Changes

  • Updated provideAuth0() to use makeEnvironmentProviders() and return EnvironmentProviders
  • Updated return type from Provider[] to EnvironmentProviders
  • Enhanced JSDoc documentation to explain the type safety benefit
  • Updated EXAMPLES.md to reflect that this restriction is now enforced at compile-time

Motivation

Previously, developers could mistakenly add provideAuth0() to a component's providers array, which could lead to unexpected behavior and runtime issues. While the documentation warned against this, there was no compile-time
enforcement.

By using makeEnvironmentProviders, TypeScript now prevents this misuse:

Before (incorrect usage would compile):

@Component({                                                                                                                                                                                                                          
  providers: [provideAuth0()] // ⚠️ Compiles but incorrect                                                                                                                                                                            
})                                                                                                                                                                                                                                    
export class MyComponent {}                                                                                                                                                                                                           

After (incorrect usage produces a type error):

@Component({                                                                                                                                                                                                                          
 providers: [provideAuth0()] // ❌ Type error: EnvironmentProviders not assignable to Provider                                                                                                                                       
})                                                                                                                                                                                                                                    
export class MyComponent {}                                                                                                                                                                                                           

Benefits

  • Type Safety: Compile-time prevention of incorrect usage
  • Better DX: Developers get immediate TypeScript feedback
  • Follows Angular Best Practices: Uses makeEnvironmentProviders as intended
  • No Breaking Changes: Existing correct usage continues to work without modification

Testing

  • ✅ All existing unit tests pass (7 suites, 122 tests)
  • ✅ Build succeeds without errors
  • ✅ No changes to public API surface beyond return type

Related

@yogeshchoudhary147 yogeshchoudhary147 requested a review from a team as a code owner January 24, 2026 09:14
@yogeshchoudhary147 yogeshchoudhary147 force-pushed the feat/provideauth0-type-safety branch 2 times, most recently from d6cd49a to 27c8788 Compare January 24, 2026 09:16
…ders

   Update provideAuth0 to return EnvironmentProviders instead of Provider[],
   preventing incorrect usage in component providers at compile-time. This
   follows Angular best practices and provides immediate TypeScript feedback
   when the function is used incorrectly.
@yogeshchoudhary147 yogeshchoudhary147 force-pushed the feat/provideauth0-type-safety branch from 27c8788 to 73f60b2 Compare January 24, 2026 09:17
@yogeshchoudhary147 yogeshchoudhary147 changed the title feat: use makeEnvironmentProviders for type-safe provideAuth0 (fixes #664) feat: use makeEnvironmentProviders for type-safe provideAuth0 Jan 24, 2026
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.

Refactor the provideAuth0 function to return an EnvironmentProviders instead of Provider[]

3 participants