From 82069da4e275eb7081cab528fa0d4b465bf57346 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 6 Feb 2022 21:40:26 +0100 Subject: [PATCH] Bugfix/fix user account creation (#682) * Fix the user account creation * Update changelog --- CHANGELOG.md | 6 ++++++ .../src/app/user/interfaces/user-item.interface.ts | 3 +++ apps/api/src/app/user/user.controller.ts | 3 ++- apps/api/src/app/user/user.service.ts | 8 ++++++-- .../src/app/pages/register/register-page.component.ts | 11 +++++++---- .../show-access-token-dialog.html | 7 ++++++- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93d379080..6be164980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.112.1 - 06.02.2022 + +### Fixed + +- Fixed the creation of the user account (missing access token) + ## 1.112.0 - 06.02.2022 ### Added diff --git a/apps/api/src/app/user/interfaces/user-item.interface.ts b/apps/api/src/app/user/interfaces/user-item.interface.ts index 338888c15..32230b69e 100644 --- a/apps/api/src/app/user/interfaces/user-item.interface.ts +++ b/apps/api/src/app/user/interfaces/user-item.interface.ts @@ -1,4 +1,7 @@ +import { Role } from '@prisma/client'; + export interface UserItem { accessToken?: string; authToken: string; + role: Role; } diff --git a/apps/api/src/app/user/user.controller.ts b/apps/api/src/app/user/user.controller.ts index a2003f9d2..a615d2f2b 100644 --- a/apps/api/src/app/user/user.controller.ts +++ b/apps/api/src/app/user/user.controller.ts @@ -85,12 +85,13 @@ export class UserController { const hasAdmin = await this.userService.hasAdmin(); - const { accessToken, id } = await this.userService.createUser({ + const { accessToken, id, role } = await this.userService.createUser({ role: hasAdmin ? 'USER' : 'ADMIN' }); return { accessToken, + role, authToken: this.jwtService.sign({ id }) diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index 527710474..5a21e9303 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -180,7 +180,11 @@ export class UserService { return hash.digest('hex'); } - public async createUser(data?: Prisma.UserCreateInput): Promise { + public async createUser(data: Prisma.UserCreateInput): Promise { + if (!data?.provider) { + data.provider = 'ANONYMOUS'; + } + let user = await this.prismaService.user.create({ data: { ...data, @@ -199,7 +203,7 @@ export class UserService { } }); - if (data.provider === Provider.ANONYMOUS) { + if (data.provider === 'ANONYMOUS') { const accessToken = this.createAccessToken( user.id, this.getRandomString(10) diff --git a/apps/client/src/app/pages/register/register-page.component.ts b/apps/client/src/app/pages/register/register-page.component.ts index 086e36e46..70cb17bdb 100644 --- a/apps/client/src/app/pages/register/register-page.component.ts +++ b/apps/client/src/app/pages/register/register-page.component.ts @@ -6,6 +6,7 @@ import { TokenStorageService } from '@ghostfolio/client/services/token-storage.s import { InfoItem } from '@ghostfolio/common/interfaces'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface'; +import { Role } from '@prisma/client'; import { format } from 'date-fns'; import { DeviceDetectorService } from 'ngx-device-detector'; import { Subject } from 'rxjs'; @@ -62,19 +63,21 @@ export class RegisterPageComponent implements OnDestroy, OnInit { this.dataService .postUser() .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(({ accessToken, authToken }) => { - this.openShowAccessTokenDialog(accessToken, authToken); + .subscribe(({ accessToken, authToken, role }) => { + this.openShowAccessTokenDialog(accessToken, authToken, role); }); } public openShowAccessTokenDialog( accessToken: string, - authToken: string + authToken: string, + role: Role ): void { const dialogRef = this.dialog.open(ShowAccessTokenDialog, { data: { accessToken, - authToken + authToken, + role }, disableClose: true, width: '30rem' diff --git a/apps/client/src/app/pages/register/show-access-token-dialog/show-access-token-dialog.html b/apps/client/src/app/pages/register/show-access-token-dialog/show-access-token-dialog.html index c47e2740c..a742bdbf6 100644 --- a/apps/client/src/app/pages/register/show-access-token-dialog/show-access-token-dialog.html +++ b/apps/client/src/app/pages/register/show-access-token-dialog/show-access-token-dialog.html @@ -1,4 +1,9 @@ -

Create Account

+

+ Create Account{{ data.role }} +