-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthController.ts
More file actions
33 lines (27 loc) · 1.18 KB
/
authController.ts
File metadata and controls
33 lines (27 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { TYPES } from "../types"
import { inject, injectable } from "inversify"
import { Request, Response, NextFunction } from "express"
import { IUserInputDTO, IAuthUserInputDTO } from "../dtos/userDTO"
import AuthService from "../services/auth"
import { myContainer } from "../inversify.config";
@injectable()
export default class AuthController {
public authService: AuthService
constructor() {
this.authService = myContainer.resolve<AuthService>(AuthService);
}
public async register(req: Request, res: Response, next: NextFunction) {
// check if name is already registered
const token = await this.authService.register(req.body as IAuthUserInputDTO)
res.status(200).send(token);
}
public async signIn(req: Request, res: Response, next: NextFunction) {
const token = await this.authService.signIn(req.body as IAuthUserInputDTO)
res.status(200).send(token);
}
public async deactivate(req: Request, res: Response, next: NextFunction) {
const token = req.headers.authorization.replace("Bearer", "");
await this.authService.deactivate(token);
res.status(200).send("User account decativated");
}
}