diff --git a/lib/auth.ts b/lib/auth.ts index 3b207c5..c5dd9a1 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -1,16 +1,16 @@ import passport from 'koa-passport'; -import Users from 'grow-db/lib/models/users'; -import { User } from 'grow-db/lib/schemas/user'; +// import Users from 'grow-db/lib/models/users'; +// import { User } from 'grow-db/lib/schemas/user'; -passport.serializeUser((user: User, done) => { done(null, user._id); }); +// passport.serializeUser((user: User, done) => { done(null, user._id); }); -passport.deserializeUser(async (id, done) => { - const user = await Users.findById(id); +// passport.deserializeUser(async (id, done) => { +// const user = await Users.findById(id); - if (user) { - done(null, user); - } +// if (user) { +// done(null, user); +// } - done('user not found', null); -}); +// done('user not found', null); +// }); diff --git a/lib/utils/password.ts b/lib/utils/password.ts index 2bb45c7..922f138 100644 --- a/lib/utils/password.ts +++ b/lib/utils/password.ts @@ -1,12 +1,12 @@ -import crypto from 'crypto'; +import { pbkdf2Sync, randomBytes } from 'crypto'; export const encrypt = (password: string) => { - const salt = crypto.randomBytes(16).toString('hex'); - const hash = crypto.pbkdf2Sync(password, salt, 10000, 512, 'sha512').toString('hex'); + const salt = randomBytes(16).toString('hex'); + const hash = pbkdf2Sync(password, salt, 10000, 512, 'sha512').toString('hex'); return `${salt}:${hash}`; }; export const verify = (test: string, secret: string) => { const [salt, hash] = secret.split(':'); - return crypto.pbkdf2Sync(test, salt, 10000, 512, 'sha512').toString('hex') === hash; + return pbkdf2Sync(test, salt, 10000, 512, 'sha512').toString('hex') === hash; };