Skip to content

Conversation

@6xtvo
Copy link
Member

@6xtvo 6xtvo commented Jun 6, 2025

Description

  • Revokes Google OAuth access token when a new Authentication collection is created
  • Created GoogleProvider class to handle token management
  • Rename StandardSecurity to StandardProvider

Fixes #111

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Manual testing (requires screenshots or videos)
  • Integration tests written (requires checks to pass)

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added thorough tests that prove my fix is effective and that my feature works
  • I've requested a review from another user

@6xtvo 6xtvo requested review from Copilot and jeffplays2005 June 6, 2025 01:50
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

This PR adds Google OAuth support by introducing a GoogleProvider for token management, integrates token revocation into the authentication flow, and renames the standard provider class.

  • Define a shared Credentials interface and relocate AUTH_COOKIE_NAME to the schemas module.
  • Implement GoogleProvider (token fetch/revoke) and invoke revocation in AuthDataService#createAuth.
  • Rename StandardSecurity to StandardProvider and update related imports/tests.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/shared/src/types/auth.ts Added Credentials interface; removed old cookie constant.
packages/shared/src/schemas/auth.ts Added AUTH_COOKIE_NAME constant.
apps/backend/src/data-layer/services/AuthDataService.ts Integrated token revocation when existing auth is detected.
apps/backend/src/business-layer/provider/standard.ts Renamed StandardSecurity to StandardProvider.
apps/backend/src/business-layer/provider/standard.test.ts Updated tests to use StandardProvider.
apps/backend/src/business-layer/provider/google.ts Introduced GoogleProvider with fetchTokens and revokeToken.
apps/backend/src/app/api/auth/google/callback/route.ts Switched to GoogleProvider.fetchTokens; cleaned up token logic.
Comments suppressed due to low confidence (3)

apps/backend/src/data-layer/services/AuthDataService.ts:13

  • The JSDoc above still states this method returns an Authentication document, but the signature now allows undefined; update the comment or ensure the method always returns a value.
public async createAuth(newAuth: CreateAuthenticationData): Promise<Authentication | undefined> {

apps/backend/src/business-layer/provider/google.ts:26

  • [nitpick] Consider adding unit tests for fetchTokens and revokeToken to validate token handling and error paths.
static async fetchTokens(code: string): Promise<Credentials | undefined> {

packages/shared/src/schemas/auth.ts:101

  • Duplicated definition of AUTH_COOKIE_NAME in different modules can lead to inconsistencies; consider centralizing this constant in one shared location.
export const AUTH_COOKIE_NAME = "auth_token"

@6xtvo 6xtvo changed the title feat: add google provider 111 refactor google auth to delete authentication if already exists Jun 6, 2025
Comment on lines 41 to 42
const usersToCreate = [casualUserMock, memberUserMock, adminUserMock]
await Promise.all(
usersToCreate.map((user) =>
payload.create({
collection: "user",
data: user,
}),
),
)
await Promise.all(usersToCreate.map(new UserDataService().createUser))
Copy link
Member

Choose a reason for hiding this comment

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

just a note, i'm reverting this because it doesn't properly set the IDs, UserDataService.createUser omits the id

@github-actions
Copy link
Contributor

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 86.01% (🎯 70%)
⬇️ -5.55%
209 / 243
🟢 Statements 85.32% (🎯 70%)
⬇️ -6.45%
215 / 252
🟢 Functions 90.14% (🎯 80%)
⬇️ -5.38%
64 / 71
🟢 Branches 71.26% (🎯 60%)
⬇️ -9.75%
62 / 87
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
apps/backend/src/app/api/auth/google/callback/route.ts 94.73%
⬆️ +11.01%
88.23%
⬆️ +2.52%
100%
🟰 ±0%
94.59%
⬆️ +11.26%
70, 86
apps/backend/src/business-layer/provider/google.ts 11.76%
⬇️ -88.24%
0%
⬇️ -100.00%
0%
⬇️ -100.00%
13.33%
⬇️ -86.67%
27-61
apps/backend/src/business-layer/provider/standard.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
apps/backend/src/data-layer/services/AuthDataService.ts 33.33%
⬇️ -66.67%
12.5%
⬇️ -87.50%
100%
🟰 ±0%
36.36%
⬇️ -63.64%
28-36
apps/backend/src/data-layer/services/UserDataService.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
Generated in workflow #1020 for commit c5bf086 by the Vitest Coverage Report Action

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.

[BACKEND] [BUG] Refactor google auth to delete authentication if already exists

4 participants