1
0
mirror of https://github.com/sasjs/server.git synced 2026-04-11 08:03:13 +00:00

chore: restructured controllers

This commit is contained in:
Saad Jutt
2021-11-11 03:40:57 +05:00
parent 7a8123eb52
commit 1814c3a1f4
27 changed files with 84 additions and 66 deletions

View File

@@ -2,11 +2,17 @@ import { Security, Route, Tags, Example, Post, Body, Query, Hidden } from 'tsoa'
import jwt from 'jsonwebtoken'
import User from '../model/User'
import { InfoJWT } from '../types'
import { removeTokensInDB, saveTokensInDB } from '../utils'
import {
generateAccessToken,
generateAuthCode,
generateRefreshToken,
removeTokensInDB,
saveTokensInDB
} from '../utils'
@Route('SASjsApi/auth')
@Tags('Auth')
export default class AuthController {
export class AuthController {
static authCodes: { [key: string]: { [key: string]: string } } = {}
static saveCode = (userId: number, clientId: string, code: string) => {
if (AuthController.authCodes[userId])
@@ -185,21 +191,6 @@ interface TokenResponse {
refreshToken: string
}
export const generateAuthCode = (data: InfoJWT) =>
jwt.sign(data, process.env.AUTH_CODE_SECRET as string, {
expiresIn: '30s'
})
export const generateAccessToken = (data: InfoJWT) =>
jwt.sign(data, process.env.ACCESS_TOKEN_SECRET as string, {
expiresIn: '1h'
})
export const generateRefreshToken = (data: InfoJWT) =>
jwt.sign(data, process.env.REFRESH_TOKEN_SECRET as string, {
expiresIn: '1day'
})
const verifyAuthCode = async (
clientId: string,
code: string