Skip to content

chore!: make nextauth and google auth integrations tree-shakeable and conditional imports (#719)#769

Open
frano-m wants to merge 8 commits intomainfrom
fran/719-next-auth
Open

chore!: make nextauth and google auth integrations tree-shakeable and conditional imports (#719)#769
frano-m wants to merge 8 commits intomainfrom
fran/719-next-auth

Conversation

@frano-m
Copy link
Contributor

@frano-m frano-m commented Feb 3, 2026

Closes #719.

This pull request refactors the authentication-related code by consolidating and reorganizing files under a new src/auth directory, standardizing naming conventions, and improving code clarity with additional documentation. It also introduces new hooks for reducer logic and session idle timers, and updates package.json to improve module exports and dependency metadata.

Authentication Module Refactor and Consolidation:

  • All authentication-related files have been moved from src/providers/authentication to a new unified src/auth directory, with consistent naming for constants, contexts, reducers, dispatchers, hooks, and types. This improves maintainability and discoverability of authentication code. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

  • Action and reducer naming has been standardized (e.g., resetStateresetAuthState, resetAuthenticationState, etc.) for clarity and to avoid naming collisions. [1] [2] [3] [4]

  • Added and improved JSDoc comments throughout the authentication codebase for better developer understanding and onboarding. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

New and Improved Hooks:

  • Introduced new custom hooks: useAuthReducer, useAuthenticationReducer, useCredentialsReducer, and useSessionIdleTimer, providing encapsulated reducer logic and session idle timeout handling for authentication state management. [1] [2] [3] [4]

Package Configuration Updates:

  • Updated package.json to add an exports field for better module resolution, especially for sub-path imports, and to mark next-auth as an optional peer dependency for improved compatibility. [1] [2]

State and Reducer Improvements:

  • Refactored state update logic in reducers for clarity and type safety, moving inline logic to separate functions and aligning with the new file structure. [1] [2]

These changes together modernize and simplify the authentication code, making it easier to maintain, extend, and use across the application.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors authentication-related code to support tree-shakeable / conditional consumption of NextAuth and Google auth integrations by reorganizing auth modules and updating package subpath exports.

Changes:

  • Consolidates auth state/types/reducers/dispatch/hooks into a new src/auth module structure and updates call sites.
  • Rehomes integration-specific code into src/nextauth, src/google, and src/terra, and updates tests accordingly.
  • Updates package.json exports and marks next-auth as an optional peer dependency; adjusts Jest config to handle react-idle-timer.

Reviewed changes

Copilot reviewed 110 out of 113 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
.gitignore Ignores new local tooling folder and packaged tarballs.
jest.config.js Adjusts Jest transforms for ESM dependency (react-idle-timer).
package.json Adds subpath exports entries and marks next-auth optional via peerDependenciesMeta.
src/auth/constants/auth.ts Aligns default auth state constants with new src/auth module layout.
src/auth/constants/authentication.ts Aligns default authentication state constants with new src/auth module layout.
src/auth/constants/credentials.ts Adds default credentials state constant in new auth module.
src/auth/constants/token.ts Aligns default token state constants with new src/auth module layout.
src/auth/contexts/auth.ts Moves auth context into src/auth/contexts.
src/auth/contexts/authentication.ts Moves authentication context into src/auth/contexts.
src/auth/contexts/credentials.ts Moves credentials context into src/auth/contexts.
src/auth/dispatch/auth.ts Standardizes auth dispatch action creators and naming.
src/auth/dispatch/authentication.ts Standardizes authentication dispatch action creators and naming.
src/auth/dispatch/credentials.ts Standardizes credentials dispatch action creators and naming.
src/auth/dispatch/token.ts Standardizes token dispatch action creators and naming.
src/auth/hooks/useAuth.ts Updates auth hook to consume new auth context location.
src/auth/hooks/useAuthReducer.ts Introduces reducer hook in new src/auth module.
src/auth/hooks/useAuthentication.ts Updates authentication hook to consume new auth context location.
src/auth/hooks/useAuthenticationReducer.ts Introduces authentication reducer hook in new src/auth module.
src/auth/hooks/useCredentials.ts Updates credentials hook to consume new credentials context location.
src/auth/hooks/useCredentialsReducer.ts Updates credentials reducer hook to new auth module layout.
src/auth/hooks/useSessionIdleTimer.ts Adds idle-timer hook under src/auth.
src/auth/reducers/auth.ts Refactors auth reducer to new module location and standardized actions.
src/auth/reducers/authentication.ts Refactors authentication reducer to new module location and standardized actions.
src/auth/reducers/credentials.ts Refactors credentials reducer to new module location and standardized actions.
src/auth/reducers/token.ts Refactors token reducer to new module location and standardized actions.
src/auth/types/auth.ts Renames/standardizes auth action/state types and adds documentation.
src/auth/types/authentication.ts Renames/standardizes authentication action/state/profile types and adds documentation.
src/auth/types/common.ts Adds shared auth types (e.g., ProviderId).
src/auth/types/credentials.ts Renames/standardizes credentials action/state types and adds documentation.
src/auth/types/login-provider.ts Adds provider-agnostic login provider type to decouple from NextAuth types.
src/auth/types/provider.ts Adds OAuth provider type under src/auth (used by integrations).
src/auth/types/token.ts Renames/standardizes token action/state types and adds documentation.
src/auth/utils/initializer.ts Adds reducer initializer utility used by auth/authentication reducer hooks.
src/components/ComponentCreator/ComponentCreator.tsx Updates useAuth import to new auth hook path.
src/components/Export/components/ExportToTerra/components/TerraSetUpForm/components/FormStep/components/AcceptTerraTOS/acceptTerraTOS.tsx Updates Terra/auth imports to new src/terra + src/auth paths.
src/components/Export/components/ExportToTerra/components/TerraSetUpForm/terraSetUpForm.tsx Updates auth imports to new src/auth paths.
src/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/components/AuthenticationMenu/authenticationMenu.tsx Updates auth-related imports to new src/auth paths.
src/components/Login/components/Buttons/buttons.tsx Updates login button rendering to provider-agnostic LoginProvider.
src/components/Login/components/Buttons/types.ts Updates button props typing to provider-agnostic LoginProvider.
src/components/Login/hooks/useUserLogin/types.ts Updates ProviderId import path to new auth types.
src/components/Login/hooks/useUserLogin/useUserLogin.ts Updates ProviderId/useAuth imports to new auth module paths.
src/components/Login/login.tsx Updates auth/provider typing to avoid hard dependency on NextAuth types.
src/components/Login/types.ts Updates login props to use provider-agnostic LoginProvider.
src/components/Authentication/components/SessionController/components/GoogleSessionController/types.ts Removes legacy Google session controller prop types (moved to integration module).
src/components/Authentication/components/SessionController/components/NextSessionController/types.ts Removes legacy NextAuth session controller prop types (moved to integration module).
src/config/entities.ts Updates imports for auth state/profile/provider id types to new src/auth types.
src/google/config.ts Reintroduces Google provider configuration under src/google.
src/google/constants.ts Defines Google provider constants and initial reducer state snapshots.
src/google/hooks/useGoogleSignInService.ts Updates Google service hook imports and types to new module layout.
src/google/hooks/useTokenReducer.ts Updates token reducer hook for Google integration to new auth/token modules.
src/google/provider.tsx Updates Google provider composition to new auth contexts/reducer hooks.
src/google/service.ts Updates Google Sign-In service to renamed dispatchers/types and new module layout.
src/google/session-controller.tsx Updates Google session controller to new auth dispatch/hook imports.
src/google/types.ts Consolidates Google integration types (provider props, session reducer/dispatch, profile types).
src/google/utils/auth.ts Adds shared Google auth utilities (request options + profile fetch helper).
src/google/utils/profile.ts Updates Google profile mapping to new auth profile types and constants.
src/hooks/authentication/auth/useAuthReducer.ts Removes legacy reducer hook (superseded by src/auth/hooks/useAuthReducer).
src/hooks/authentication/authentication/useAuthenticationReducer.ts Removes legacy reducer hook (superseded by src/auth/hooks/useAuthenticationReducer).
src/hooks/authentication/profile/types.ts Updates profile types import to new auth types.
src/hooks/authentication/profile/useProfile.ts Updates auth hook/type imports to new src/auth locations.
src/hooks/authentication/providers/types.ts Updates ProviderId import to new auth types.
src/hooks/authentication/providers/useProviders.ts Updates ProviderId import to new auth types.
src/hooks/authentication/session/useSessionActive.ts Updates auth/authentication type imports to new src/auth locations.
src/hooks/authentication/terra/useAuthenticationForm.ts Updates Terra imports/types to new src/terra module structure.
src/hooks/authentication/terra/useAuthenticationNIHExpiry.ts Updates Terra imports/types to new src/terra module structure.
src/hooks/authentication/token/types.ts Updates credentials type import to new auth types.
src/hooks/authentication/token/useToken.ts Updates credentials hook import to new auth hooks.
src/nextauth/constants.ts Updates NextAuth status maps to new auth status enums/types.
src/nextauth/hooks/useNextAuthService.ts Updates NextAuth service hook imports/types to new auth modules and refactored service.
src/nextauth/provider.tsx Updates NextAuth provider wiring to new auth contexts/reducer hooks and new session controller.
src/nextauth/service.ts Updates NextAuth service types/imports and adds documentation.
src/nextauth/session-controller.tsx Updates NextAuth session controller to new auth dispatch/hook imports.
src/nextauth/types.ts Adds/updates NextAuth integration prop types and documentation.
src/nextauth/utils.ts Updates NextAuth mapping utilities to new auth types and adds/keeps mapping logic.
src/providers/authentication/auth/actions.ts Removes legacy auth action helper (logic moved into reducer module).
src/providers/authentication/authentication/actions.ts Removes legacy authentication action helper (logic moved into reducer module).
src/providers/authentication/common/types.ts Removes legacy shared ProviderId type (replaced by src/auth/types/common).
src/providers/authentication/credentials/actions.ts Removes legacy credentials action helper (logic moved into reducer module).
src/providers/authentication/credentials/constants.ts Removes legacy credentials constants (moved to src/auth/constants/credentials).
src/providers/authentication/terra/hooks/common/entities.ts Removes legacy Terra common entities (replaced by src/terra/types/*).
src/providers/authentication/terra/hooks/common/utils.ts Removes legacy Terra common utilities (replaced by src/terra/utils).
src/providers/authentication/terra/hooks/utils.ts Removes legacy Terra service endpoint utilities (replaced by src/terra/utils).
src/providers/authentication/terra/types.ts Removes legacy Terra types (replaced by src/terra/types/*).
src/providers/authentication/terra/utils.ts Removes legacy Terra utils (replaced by src/terra/utils).
src/providers/googleSignInAuthentication/common/types.ts Removes legacy Google Sign-In types (moved to src/google/types).
src/providers/googleSignInAuthentication/constants.ts Removes legacy Google Sign-In constants (moved to src/google/constants).
src/providers/googleSignInAuthentication/profile/types.ts Removes legacy Google profile/token types (moved to src/google/types).
src/providers/googleSignInAuthentication/service/constants.ts Removes legacy Google service constants/config (moved to src/google/config).
src/providers/googleSignInAuthentication/types.ts Removes legacy Google provider props types (moved to src/google/types).
src/providers/loginGuard/provider.tsx Updates useAuth import to new auth hook path.
src/terra/constants.ts Defines Terra login status constants and a union response type.
src/terra/context.ts Updates Terra context to new constants/types module layout.
src/terra/hooks/useFetchProfiles.ts Updates Terra profile fetch orchestrator to new Terra/auth modules and adds docs.
src/terra/hooks/useFetchTerraNIHProfile.ts Updates Terra NIH fetch hook to new Terra types/utils module layout.
src/terra/hooks/useFetchTerraProfile.ts Updates Terra profile fetch hook to new Terra types/utils module layout.
src/terra/hooks/useFetchTerraTermsOfService.ts Updates Terra TOS fetch hook to new Terra types/utils module layout.
src/terra/hooks/useTerraProfile.ts Updates Terra hook imports to new Terra context/types.
src/terra/provider.tsx Updates Terra provider to new auth dispatch/hook modules and adds docs.
src/terra/types/common.ts Introduces shared Terra types/enums for request/login state.
src/terra/types/context.ts Introduces Terra context props type.
src/terra/types/terra-nih.ts Introduces typed Terra NIH response model.
src/terra/types/terra-profile.ts Introduces typed Terra profile response model.
src/terra/types/terra-tos.ts Introduces typed Terra Terms of Service response model.
src/terra/utils.ts Consolidates Terra utility helpers (auth request options, service lookup, profile status).
src/views/LoginView/loginView.tsx Updates login view providers typing to provider-agnostic LoginProvider.
tests/authReducer.test.ts Adds/updates reducer tests for new authReducer behavior/actions.
tests/authenticationReducer.test.ts Adds/updates reducer tests for new authenticationReducer behavior/actions.
tests/getProfileStatus.test.ts Updates Terra profile status tests to new Terra module import paths.
tests/googleProfile.test.ts Adds tests for Google profile mapping utility.
tests/nextAuthUtils.test.ts Adds tests for NextAuth session-to-state mapping utilities.
tests/provider.test.tsx Updates login guard provider test mocks/imports to new auth module paths.
tests/terraProfileProvider.test.tsx Updates Terra profile provider test mocks/imports to new auth/Terra module paths.
tests/useSessionActive.test.ts Updates session activity test imports to new auth module paths.

frano-m and others added 3 commits February 4, 2026 08:27
…ile (#719)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@frano-m frano-m changed the title chore: make nextauth and google auth integrations tree-shakeable and conditional imports (#719) chore!: make nextauth and google auth integrations tree-shakeable and conditional imports (#719) Feb 3, 2026
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

Make NextAuth and Google Auth integrations tree-shakeable and support conditional imports

3 participants