remove mongoose lines

This commit is contained in:
andrzej 2024-06-03 13:00:42 +02:00
parent 4cbed331b1
commit 6eb94b8520
2 changed files with 0 additions and 47 deletions

View File

@ -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())

View File

@ -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<boolean>
}
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))
}