added auth service
This commit is contained in:
parent
d8bb908b03
commit
95fd50a638
|
@ -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);
|
||||||
|
|
|
@ -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);
|
|
@ -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();
|
Loading…
Reference in New Issue