Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Bugfix/resolve exception in user service for non-existent user (#7435)

Thomas Kaul13788f5060d5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0e93211b3c..286b2a27c3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Refreshed the cryptocurrencies list
- Upgraded `prettier` from version `3.8.4` to `3.9.6`
+### Fixed
+
+- Resolved an exception in the user service when getting a non-existent user
+
## 3.34.0 - 2026-07-25
### Changed
diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts
index 6304c81ea1..648f36cbf5 100644
--- a/apps/api/src/app/user/user.service.ts
+++ b/apps/api/src/app/user/user.service.ts
@@ -231,22 +231,7 @@ export class UserService {
public async user(
userWhereUniqueInput: Prisma.UserWhereUniqueInput
): Promise<UserWithSettings | null> {
- const {
- _count,
- accessesGet,
- accessToken,
- accounts,
- analytics,
- authChallenge,
- createdAt,
- id,
- provider,
- role,
- settings,
- subscriptions,
- thirdPartyId,
- updatedAt
- } = await this.prismaService.user.findUnique({
+ const userFromDatabase = await this.prismaService.user.findUnique({
include: {
_count: {
select: {
@@ -264,6 +249,27 @@ export class UserService {
where: userWhereUniqueInput
});
+ if (!userFromDatabase) {
+ return null;
+ }
+
+ const {
+ _count,
+ accessesGet,
+ accessToken,
+ accounts,
+ analytics,
+ authChallenge,
+ createdAt,
+ id,
+ provider,
+ role,
+ settings,
+ subscriptions,
+ thirdPartyId,
+ updatedAt
+ } = userFromDatabase;
+
const activitiesCount = _count?.activities ?? 0;
const user: UserWithSettings = {
@@ -283,16 +289,16 @@ export class UserService {
analytics?.dataProviderGhostfolioDailyRequests
};
- if (user?.settings) {
+ if (user.settings) {
if (!user.settings.settings) {
user.settings.settings = {};
}
- } else if (user) {
+ } else {
// Set default settings if needed
user.settings = {
settings: {},
updatedAt: new Date(),
- userId: user?.id
+ userId: user.id
};
}