Bugfix/fix user account creation (#682)
* Fix the user account creation * Update changelog
This commit is contained in:
parent
07656c6a95
commit
82069da4e2
@ -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/),
|
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).
|
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
|
## 1.112.0 - 06.02.2022
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
import { Role } from '@prisma/client';
|
||||||
|
|
||||||
export interface UserItem {
|
export interface UserItem {
|
||||||
accessToken?: string;
|
accessToken?: string;
|
||||||
authToken: string;
|
authToken: string;
|
||||||
|
role: Role;
|
||||||
}
|
}
|
||||||
|
@ -85,12 +85,13 @@ export class UserController {
|
|||||||
|
|
||||||
const hasAdmin = await this.userService.hasAdmin();
|
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'
|
role: hasAdmin ? 'USER' : 'ADMIN'
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
accessToken,
|
accessToken,
|
||||||
|
role,
|
||||||
authToken: this.jwtService.sign({
|
authToken: this.jwtService.sign({
|
||||||
id
|
id
|
||||||
})
|
})
|
||||||
|
@ -180,7 +180,11 @@ export class UserService {
|
|||||||
return hash.digest('hex');
|
return hash.digest('hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createUser(data?: Prisma.UserCreateInput): Promise<User> {
|
public async createUser(data: Prisma.UserCreateInput): Promise<User> {
|
||||||
|
if (!data?.provider) {
|
||||||
|
data.provider = 'ANONYMOUS';
|
||||||
|
}
|
||||||
|
|
||||||
let user = await this.prismaService.user.create({
|
let user = await this.prismaService.user.create({
|
||||||
data: {
|
data: {
|
||||||
...data,
|
...data,
|
||||||
@ -199,7 +203,7 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.provider === Provider.ANONYMOUS) {
|
if (data.provider === 'ANONYMOUS') {
|
||||||
const accessToken = this.createAccessToken(
|
const accessToken = this.createAccessToken(
|
||||||
user.id,
|
user.id,
|
||||||
this.getRandomString(10)
|
this.getRandomString(10)
|
||||||
|
@ -6,6 +6,7 @@ import { TokenStorageService } from '@ghostfolio/client/services/token-storage.s
|
|||||||
import { InfoItem } from '@ghostfolio/common/interfaces';
|
import { InfoItem } from '@ghostfolio/common/interfaces';
|
||||||
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
|
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
|
||||||
import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface';
|
import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface';
|
||||||
|
import { Role } from '@prisma/client';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
import { DeviceDetectorService } from 'ngx-device-detector';
|
import { DeviceDetectorService } from 'ngx-device-detector';
|
||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
@ -62,19 +63,21 @@ export class RegisterPageComponent implements OnDestroy, OnInit {
|
|||||||
this.dataService
|
this.dataService
|
||||||
.postUser()
|
.postUser()
|
||||||
.pipe(takeUntil(this.unsubscribeSubject))
|
.pipe(takeUntil(this.unsubscribeSubject))
|
||||||
.subscribe(({ accessToken, authToken }) => {
|
.subscribe(({ accessToken, authToken, role }) => {
|
||||||
this.openShowAccessTokenDialog(accessToken, authToken);
|
this.openShowAccessTokenDialog(accessToken, authToken, role);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public openShowAccessTokenDialog(
|
public openShowAccessTokenDialog(
|
||||||
accessToken: string,
|
accessToken: string,
|
||||||
authToken: string
|
authToken: string,
|
||||||
|
role: Role
|
||||||
): void {
|
): void {
|
||||||
const dialogRef = this.dialog.open(ShowAccessTokenDialog, {
|
const dialogRef = this.dialog.open(ShowAccessTokenDialog, {
|
||||||
data: {
|
data: {
|
||||||
accessToken,
|
accessToken,
|
||||||
authToken
|
authToken,
|
||||||
|
role
|
||||||
},
|
},
|
||||||
disableClose: true,
|
disableClose: true,
|
||||||
width: '30rem'
|
width: '30rem'
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
<h1 mat-dialog-title i18n>Create Account</h1>
|
<h1 mat-dialog-title>
|
||||||
|
<span i18n>Create Account</span
|
||||||
|
><span *ngIf="data.role === 'ADMIN'" class="badge badge-light ml-2"
|
||||||
|
>{{ data.role }}</span
|
||||||
|
>
|
||||||
|
</h1>
|
||||||
<div mat-dialog-content>
|
<div mat-dialog-content>
|
||||||
<div>
|
<div>
|
||||||
<mat-form-field appearance="outline" class="w-100">
|
<mat-form-field appearance="outline" class="w-100">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user