Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @description Default Imports
- */
- import { Request, Response } from 'express';
- import chalk from 'chalk';
- /**
- * @description Schema Imports
- */
- import { Credentials } from './../schemas/credentials.schema';
- export class AuthenticationController {
- public authenticate(req: Request, res: Response) {
- try {
- Credentials.authenticate()(req.body.username, req.body.password, (err: any, user: any, error: any) => {
- if (error) {
- switch (error.name) {
- case 'IncorrectUsernameError':
- {
- res.status(422).json({ message: error.message });
- }
- break;
- case 'IncorrectPasswordError':
- {
- res.status(422).json({ message: error.message });
- }
- break;
- default:
- break;
- }
- } else {
- res.status(200).json({ status: 200, message: 'Authentication Successfull!', admin: user.admin });
- }
- });
- } catch (error) {
- console.error(chalk.redBright(error));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement