updated user API route
This commit is contained in:
parent
284171c7e9
commit
ceea334375
@ -17,28 +17,26 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
const username = req.body.username;
|
const username = req.body.username;
|
||||||
const password = req.body.password;
|
const password = req.body.password;
|
||||||
console.log(req.body);
|
await MUser.sync()
|
||||||
const user = await MUser.sync()
|
var user = await MUser.findOne({ where: { username: username } });
|
||||||
.then(async f => {
|
if (user != undefined){
|
||||||
return await MUser.findOne({ where: { username: username } });
|
res.status(500).json("User with that username already exists");
|
||||||
})
|
return;
|
||||||
.then(async user => {
|
}
|
||||||
if (user == undefined) {
|
const hash = await hashPassword(password)
|
||||||
const hash = await hashPassword(password)
|
user = await MUser.create({
|
||||||
return await MUser.create({
|
username: username,
|
||||||
username: username,
|
password: hash
|
||||||
password: hash
|
})
|
||||||
})
|
res.status(200).json(user);
|
||||||
}
|
return;
|
||||||
else{
|
}
|
||||||
throw "User with that username already exists";
|
if (req.method === 'GET') {
|
||||||
}
|
const username = req.body.username;
|
||||||
})
|
const password = req.body.password;
|
||||||
.then(user =>{
|
await MUser.sync()
|
||||||
res.status(200).json(user)
|
var users = await MUser.findAll();
|
||||||
})
|
res.status(200).json(users);
|
||||||
.catch(error => {
|
return;
|
||||||
res.status(500).json(error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user