1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-11 11:44:34 +00:00

fix: fetch client from DB for each request

This commit is contained in:
Saad Jutt
2022-04-24 04:16:13 +05:00
parent 51f6aa34a1
commit 4ad8c81e49
3 changed files with 6 additions and 30 deletions

View File

@@ -1,6 +1,7 @@
import { Security, Route, Tags, Example, Post, Body, Query, Hidden } from 'tsoa'
import jwt from 'jsonwebtoken'
import User from '../model/User'
import Client from '../model/Client'
import { InfoJWT } from '../types'
import {
generateAccessToken,
@@ -81,6 +82,9 @@ export class AuthController {
const authorize = async (data: any): Promise<AuthorizeResponse> => {
const { username, password, clientId } = data
const client = await Client.findOne({ clientId })
if (!client) throw new Error('Invalid clientId.')
// Authenticate User
const user = await User.findOne({ username })
if (!user) throw new Error('Username is not found.')