v1.0.0 #28

Merged
bizcochito merged 147 commits from develop into main 2024-01-14 19:49:34 +00:00
3 changed files with 14 additions and 5 deletions
Showing only changes of commit 95fd50a638 - Show all commits

View File

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

View File

@ -1,11 +1,11 @@
import mongoose, { Document } from "mongoose"; import mongoose, { Document } from "mongoose";
export interface App extends Document { export interface Auth extends Document {
app: String, app: String,
secret: String secret: String
} }
const AppSchema = new mongoose.Schema({ const AuthSchema = new mongoose.Schema({
app: { app: {
type: String, type: String,
required: true, 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();