Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
505 B
2
Indexable
Never
const webToken = require('jsonwebtoken');
const { User } = require('../models');

const loginAuth = async (email, password) => {
  const user = await User.findOne({ where: { email } });
  if (!user || user.password !== password) return null;

  const passwordWithoutHash = process.env.passwordWithoutHash || 'raisfonogreis';
  const token = webToken.sign(
    { id: user.id, email: user.email },
    passwordWithoutHash,
    { expiresIn: '1d' },
  );
  return token;
};

module.exports = {
  loginAuth,
};
Leave a Comment