Switched to hased tokens based on uuid (to be canged)

ref #56
This commit is contained in:
Nicolai Ort 2020-12-29 20:20:59 +01:00
parent 1b74b21420
commit bb24ed53a4
1 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,8 @@
import * as argon2 from "argon2";
import { IsBoolean, IsOptional, IsString } from 'class-validator';
import crypto from "crypto";
import * as uuid from 'uuid';
import { StatsClient } from '../entities/StatsClient';
/**
* This classed is used to create a new StatsClient entity from a json body (post request).
*/
@ -22,11 +24,11 @@ export class CreateStatsClient {
/**
* Converts this to a StatsClient entity.
*/
public toStatsClient(): StatsClient {
public async toStatsClient(): Promise<StatsClient> {
let newClient: StatsClient = new StatsClient();
newClient.description = this.description;
newClient.key = crypto.randomBytes(20).toString('hex');
newClient.key = await argon2.hash(uuid.v4());
if (this.enabled === undefined || this.enabled === null) { newClient.enabled = true; }
else { newClient.enabled = this.enabled }