first jwt generation

ref #12
This commit is contained in:
Philipp Dormann 2020-12-04 23:03:24 +01:00
parent 6244c969af
commit 6ae0c1b955

View File

@ -1,4 +1,5 @@
import { IsEmail, IsOptional, IsString } from 'class-validator'; import { IsEmail, IsOptional, IsString } from 'class-validator';
import * as jsonwebtoken from 'jsonwebtoken';
import { getConnectionManager } from 'typeorm'; import { getConnectionManager } from 'typeorm';
import { PasswordNeededError, UserNotFoundError } from '../../errors/AuthError'; import { PasswordNeededError, UserNotFoundError } from '../../errors/AuthError';
import { UsernameOrEmailNeededError } from '../../errors/UserErrors'; import { UsernameOrEmailNeededError } from '../../errors/UserErrors';
@ -29,12 +30,14 @@ export class CreateAuth {
if (found_users.length === 0) { if (found_users.length === 0) {
throw new UserNotFoundError() throw new UserNotFoundError()
} else { } else {
const found_user = found_users[0]
const token = jsonwebtoken.sign(found_user, "sec")
// TODO: jwt creation // TODO: jwt creation
newAuth.access_token = "" newAuth.access_token = token
newAuth.refresh_token = "" newAuth.refresh_token = token
newAuth.access_token_expires_at = 1587349200 newAuth.access_token_expires_at = 1587349200
newAuth.refresh_token_expires_at = 1587349200 newAuth.refresh_token_expires_at = 1587349200
console.log(newAuth) console.log(newAuth)
} }