parent
c4b7ece974
commit
6cb01090d0
26
src/controllers/AuthController.ts
Normal file
26
src/controllers/AuthController.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { Body, JsonController, Post } from 'routing-controllers';
|
||||||
|
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
|
import { InvalidCredentialsError } from '../errors/AuthError';
|
||||||
|
import { UserNotFoundError } from '../errors/UserErrors';
|
||||||
|
import { CreateAuth } from '../models/creation/CreateAuth';
|
||||||
|
|
||||||
|
@JsonController('/auth')
|
||||||
|
export class AuthController {
|
||||||
|
constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post("/login")
|
||||||
|
@ResponseSchema(InvalidCredentialsError)
|
||||||
|
@ResponseSchema(UserNotFoundError)
|
||||||
|
@OpenAPI({ description: 'Create a new access token object' })
|
||||||
|
async post(@Body({ validate: true }) createAuth: CreateAuth) {
|
||||||
|
let auth;
|
||||||
|
try {
|
||||||
|
auth = await createAuth.toAuth();
|
||||||
|
console.log(auth);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
return auth
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,9 @@
|
|||||||
import { IsEmail, IsOptional, IsString } from 'class-validator';
|
import { IsEmail, IsOptional, IsString } from 'class-validator';
|
||||||
|
import { getConnectionManager } from 'typeorm';
|
||||||
import { PasswordNeededError } from '../../errors/AuthError';
|
import { PasswordNeededError } from '../../errors/AuthError';
|
||||||
import { UsernameOrEmailNeededError } from '../../errors/UserErrors';
|
import { UsernameOrEmailNeededError } from '../../errors/UserErrors';
|
||||||
import { Auth } from '../entities/Auth';
|
import { Auth } from '../entities/Auth';
|
||||||
|
import { User } from '../entities/User';
|
||||||
|
|
||||||
export class CreateAuth {
|
export class CreateAuth {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@ -22,9 +24,10 @@ export class CreateAuth {
|
|||||||
if (!this.password) {
|
if (!this.password) {
|
||||||
throw new PasswordNeededError()
|
throw new PasswordNeededError()
|
||||||
}
|
}
|
||||||
// const found = await getConnectionManager().get().getRepository(UserGroup).find({ id: g });
|
const found = await getConnectionManager().get().getRepository(User).find({ where: [{ username: this.username }, { email: this.email }] });
|
||||||
|
console.log(found);
|
||||||
|
|
||||||
// TODO: jwt creation + return
|
// TODO: jwt creation
|
||||||
newAuth.access_token = ""
|
newAuth.access_token = ""
|
||||||
newAuth.refresh_token = ""
|
newAuth.refresh_token = ""
|
||||||
newAuth.access_token_expires_at = 1587349200
|
newAuth.access_token_expires_at = 1587349200
|
||||||
|
Loading…
x
Reference in New Issue
Block a user