Created
January 15, 2021 07:43
-
-
Save kuc-arc-f/c4463b7780f4bddbdd3b59da1837394f to your computer and use it in GitHub Desktop.
Next.js, Login auth sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bcrypt = require('bcrypt'); | |
var AUTH_MAIL = "hoge@example.com" | |
var AUTH_PASSWORD="1111" | |
// | |
export default async (req, res) => { | |
try{ | |
if (req.method === "POST") { | |
var data = req.body | |
console.log(data) | |
var retArr= {ret:0, user_id:0} | |
let hashed_password = bcrypt.hashSync(AUTH_PASSWORD, 10); | |
if (data.mail === AUTH_MAIL | |
&& bcrypt.compareSync(data.password, hashed_password )){ | |
//console.log("OK-auth:", data.mail) | |
retArr.ret = 1 | |
return res.json(retArr); | |
}else{ | |
//console.log("NG-auth:", data.mail) | |
return res.json(retArr); | |
} | |
// return res.status(403).send(""); | |
} | |
return res.status(404).send(""); | |
} catch (err) { | |
console.log(err); | |
res.status(500).send(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment