mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-26 01:06:00 +03:00
[PR #5210] [CLOSED] refactor: use singleton PrismaService and add env var guards for safety #5110
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5110
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5210
Author: @Krishprajapati15
Created: 6/28/2025
Status: ❌ Closed
Base:
main← Head:main📝 Commits (8)
9842df2refactor(auth): enhance GithubStrategy with type safety, error handling, and secure validationb001509refactor(auth): apply robust type safety and error handling to all strategiesbdc82aerefactor(auth): enhance GithubStrategy with type safety, error handling, and secure validationf1e2f4arefactor(auth): apply robust type safety and error handling to all strategiesd73e0f3refactor: improve email validation and unused done()a45dcb5chore: remove unnecessary Promise return types3cb85earefactor: use singleton PrismaService and add env var guards for safetya6c046crefactor: use singleton PrismaService and add env var guards for safety📊 Changes
7 files changed (+329 additions, -119 deletions)
View changed files
📝
packages/hoppscotch-backend/src/auth/strategies/github.strategy.ts(+71 -12)📝
packages/hoppscotch-backend/src/auth/strategies/google.strategy.ts(+69 -15)📝
packages/hoppscotch-backend/src/auth/strategies/jwt.strategy.ts(+13 -9)📝
packages/hoppscotch-backend/src/auth/strategies/microsoft.strategy.ts(+81 -14)📝
packages/hoppscotch-backend/src/auth/strategies/rt-jwt.strategy.ts(+14 -10)📝
packages/hoppscotch-backend/src/errors.ts(+7 -0)📝
packages/hoppscotch-backend/src/infra-config/helper.ts(+74 -59)📄 Description
What was the problem?
Previously, the codebase instantiated a new
PrismaServiceinside each helper function that interacted with the database. This approach could lead to:Additionally, the code accessed environment variables (e.g.,
process.env.XYZ) directly without checking if they were defined. If any expected environment variable was missing, this would cause:.split(',')onundefinedthrows a runtime error.What has changed?
Singleton PrismaService:
All database helper functions now accept a shared PrismaService instance as a parameter, instead of creating new ones internally. This ensures a single connection pool is used, following best practices for database usage and resource management.
Environment variable guards:
Every access to an environment variable now uses a fallback (
?? '') to guarantee a string value is used. This prevents runtime errors and ensures the app doesn't crash if an env variable is missing.Before
After
Summary:
This PR improves the reliability and stability of the infra config helper code by ensuring only a single PrismaService instance is used and by adding guards for all environment variable accesses.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.