updated codegen, added client query generation, etc.
This commit is contained in:
parent
864f37a652
commit
9518787206
17 changed files with 5244 additions and 445 deletions
25
app/server/graphql/resolvers/auth/login.ts
Normal file
25
app/server/graphql/resolvers/auth/login.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import bcrypt from 'bcrypt';
|
||||
|
||||
const usersDB = {
|
||||
users: require('../model/users.json'),
|
||||
setUsers: function (data) {
|
||||
this.users = data;
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogin = async (req, res) => {
|
||||
const { user, pwd } = req.body;
|
||||
if (!user || !pwd) res.status(400).json({ message: 'Username and password are required.' });
|
||||
const foundUser = usersDB.users.find(person => person.username === user);
|
||||
if (!foundUser) return res.sendStatus(401); // unauthorized
|
||||
// evaluate password
|
||||
const match = await bcrypt.compare(pwd, foundUser.password);
|
||||
if (match) {
|
||||
// create JWTs
|
||||
res.json({ success: `User ${user} is logged in.` });
|
||||
} else {
|
||||
res.sendStatus(401);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { handleLogin };
|
||||
Loading…
Add table
Add a link
Reference in a new issue