diff --git a/index.mts b/index.mts index f717fc6..d4c7748 100644 --- a/index.mts +++ b/index.mts @@ -1,14 +1,10 @@ import express from "express" -import mongoose from "mongoose" import passport from "passport" import bodyParser from "body-parser" import { db } from "./db.mjs" import { default as routes } from "./routes/routes.mjs" import { default as secureRoute } from "./routes/secure-routes.mjs" import "./auth/auth.mjs" -mongoose.connect("mongodb://127.0.0.1:27017/passport-jwt", {}); -mongoose.connection.on('error', error => console.log(error)); -mongoose.Promise = global.Promise; const app = express() app.use(passport.initialize()) diff --git a/model/model.mts b/model/model.mts index 8bcf0c9..53e6009 100644 --- a/model/model.mts +++ b/model/model.mts @@ -1,47 +1,4 @@ -import mongoose from "mongoose"; import bcrypt from "bcrypt" - -const Schema = mongoose.Schema - -const UserSchema = new Schema({ - email: { - type: String, - required: true, - unique: true - }, - password: { - type: String, - required: true - } -}) - -UserSchema.pre( - "save", - async function(next) { - const hash = await bcrypt.hash(this.password, 10) - this.password = hash; - next(); - } -) - -UserSchema.methods.isValidPassword = async function(password: string) { - const compare = await bcrypt.compare(password, this.password) - return compare -} - -export interface User { - email: string; - password: string; - isValidPassword: (password: string) => Promise -} - -export const UserModel = mongoose.model("user", UserSchema) - -export interface User { - username: string; - password: string; -} - export async function encryptPwd(pwd: string) { return Promise.resolve(bcrypt.hash(pwd, 10)) }