added auth service

This commit is contained in:
Alie 2023-12-27 18:29:20 +01:00
parent d8bb908b03
commit 95fd50a638
3 changed files with 14 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import jwt from "jsonwebtoken";
import AppModel from "../models/AppModel";
import AuthService from "../services/AuthService";
import { Request, Response, NextFunction } from "express";
const authTokenSecret = process.env.JWTSECRET || "badsecret";
@ -10,7 +10,7 @@ class AuthControler {
const { app, secret } = req.body;
// Filter app from the apps by app and secret
const authenticated = await AppModel.findOne(app, secret);
const authenticated = await AuthService.find(app, secret);
if (authenticated) {
console.log("Authenticated app ", authenticated.app);

View File

@ -1,11 +1,11 @@
import mongoose, { Document } from "mongoose";
export interface App extends Document {
export interface Auth extends Document {
app: String,
secret: String
}
const AppSchema = new mongoose.Schema({
const AuthSchema = new mongoose.Schema({
app: {
type: String,
required: true,
@ -16,4 +16,4 @@ const AppSchema = new mongoose.Schema({
},
});
export default mongoose.model("apps", AppSchema);
export default mongoose.model("auth", AuthSchema);

View File

@ -0,0 +1,9 @@
import AuthModel, { Auth } from "../models/AuthModel";
class AuthService {
async find(app: String, secret: String): Promise<Auth | null> {
return await AuthModel.findOne(app, secret);
}
}
export default new AuthService();