Skip to content

Extract shared Firebase authentication logic into a reusable service #311

Description

@jikrana1

Problem

The googleAuth and githubAuth controllers contain a significant amount of duplicated logic.

Both authentication flows perform the following operations:

  • Verify the Firebase ID token.
  • Extract user information from the decoded token.
  • Validate that an email exists.
  • Find or create a user in the database.
  • Generate JWT access and refresh tokens.
  • Set the refresh token cookie.
  • Return the authenticated user response.

Duplicating the same authentication workflow across multiple controllers makes the code harder to maintain and increases the risk of inconsistencies when changes are required.


Suggested Improvement

Extract the common Firebase authentication workflow into a reusable service or helper.

Each controller should only specify provider-specific behavior (such as the provider name or default display name) and delegate the shared authentication logic to the reusable service.


Expected Result

  • Shared Firebase authentication logic is implemented in a single place.
  • googleAuth and githubAuth controllers become smaller and easier to read.
  • Future Firebase providers can be added with minimal code duplication.
  • Existing authentication behavior remains unchanged.

Possible Implementation

  • Create a service such as src/services/firebaseAuthService.js.
  • Move the shared authentication workflow into the service.
  • Pass provider-specific values (e.g. google or github) as parameters.
  • Update both controllers to use the shared service.

Metadata

Metadata

Assignees

Labels

SSoC26Program label for Social Summer of Code Season 5.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions