UP checkAuthenticated.js -> ts

This commit is contained in:
Nikola Petrov 2024-07-16 14:24:01 +02:00
parent 9452dcf90e
commit c5b2e2d82b
6 changed files with 21 additions and 7 deletions

View File

@ -1,7 +1,8 @@
import { type Express, type NextFunction, type Request, type Response } from "express";
import UserModel from '../models/userModel';
var UserModel = require('../models/userModel');
async function checkAuthenticated(req, res, next) {
async function checkAuthenticated(req: Request, res: Response, next: NextFunction) {
try {
const password = req.body.pass;
const userFound = await UserModel.findOne({ pass: password });
@ -16,4 +17,4 @@ async function checkAuthenticated(req, res, next) {
}
}
module.exports = checkAuthenticated;
export default checkAuthenticated;

13
miscellaneous/custom.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
declare namespace Express {
export interface Request {
user?: Document<unknown, {}, {
pass?: string | undefined;
omdb_key?: string | undefined;
twitch_client_id?: string | undefined;
twitch_client_secret?: string | undefined;
mac_address?: string | undefined;
}>
}
}

View File

@ -1,6 +1,6 @@
var express = require('express');
var router = express.Router();
const checkAuthenticated = require('../../middleware/checkAuthenticated.js');
const checkAuthenticated = require('../../miscellaneous/checkAuthenticated.js').default;
var mediaRouter = require('./mediaRouter');
var gameRouter = require('./gameRouter');

View File

@ -1,7 +1,7 @@
var express = require('express');
var router = express.Router();
var gameController = require('../../controllers/gameController.js');
var checkAuthenticated = require('../../middleware/checkAuthenticated.js');
var checkAuthenticated = require('../../miscellaneous/checkAuthenticated.js').default;
router.get('/', gameController.list);

View File

@ -1,7 +1,7 @@
var express = require('express');
var router = express.Router();
var mediaController = require('../../controllers/mediaController.js');
var checkAuthenticated = require('../../middleware/checkAuthenticated.js');
var checkAuthenticated = require('../../miscellaneous/checkAuthenticated.js').default;
router.get('/', mediaController.list);

View File

@ -1,7 +1,7 @@
var express = require('express');
var router = express.Router();
var userController = require('../controllers/userController.js');
const checkAuthenticated = require('../middleware/checkAuthenticated.js');
const checkAuthenticated = require('../miscellaneous/checkAuthenticated.js').default;
/* GET home page. */
router.get('/', function (req, res, next) {