Updates
This commit is contained in:
20
lib/auth.ts
20
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);
|
||||
// });
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user