auth #6
|
@ -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);
|
||||
|
|
|
@ -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);
|
|
@ -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