private: adds tokens controller

adds private api
adds AuthTokenDto and AuthTokenWithSecretDto
adds necessary methods in the users service
adds RandomnessError

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-01-16 23:53:46 +01:00 committed by David Mehren
parent 1c7452d066
commit 80c7ae2fa9
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
10 changed files with 248 additions and 12 deletions

View file

@ -4,22 +4,38 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import {
Column,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm/index';
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { User } from './user.entity';
import { Type } from 'class-transformer';
@Entity()
export class AuthToken {
@PrimaryGeneratedColumn()
id: number;
@ManyToOne((_) => User, (user) => user.authToken)
@ManyToOne((_) => User, (user) => user.authTokens)
user: User;
@Column()
identifier: string;
@Type(() => Date)
@Column('text')
createdAt: Date;
@Column()
accessToken: string;
public static create(
user: User,
identifier: string,
accessToken: string,
): Pick<AuthToken, 'user' | 'accessToken'> {
const newToken = new AuthToken();
newToken.user = user;
newToken.identifier = identifier;
newToken.accessToken = accessToken;
newToken.createdAt = new Date();
return newToken;
}
}