Last active
September 20, 2020 04:43
-
-
Save disaada/d42aeda7e4c52b8bb1d1e7b9997a7833 to your computer and use it in GitHub Desktop.
Revisions
-
disaada revised this gist
Sep 20, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,9 +6,9 @@ app.post('/signin', (req, res) => { .then((data) => { /* data dari db didapat, bandingkan password yg diinput dengan yg ada di db */ if (data && (bcrypt.compareSync(password, data.password))) { /* buat token menggunakan jwt.sign(data, 'secretkey', waktu_expired) */ const token = jwt.sign({ data }, 'secret', { expiresIn: '1h' }) /* mengirimkan respon ke client berupa pesan */ res.json({ data, token, message: 'signin success!' }) } /* kalau perbandingan password tidak cocok, kirim pesan peringatan */ else res.json({ message: 'invalid email or password!' }) -
disaada revised this gist
Sep 20, 2020 . 1 changed file with 5 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,19 @@ app.post('/signin', (req, res) => { /* step 1 : mengambil data email dan password yang telah diisi oleh user */ const { email, password } = req.body /* step 2 : mengambil data user di db berdasarkan email yang dimasukkan user */ Model.user.findOne({ where: { email } }) .then((data) => { /* data dari db didapat, bandingkan password yg diinput dengan yg ada di db */ if (data && (bcrypt.compareSync(password, data.password))) { /* buat token menggunakan jwt.sign(data, 'secretkey', waktu_expired) */ const token = jwt.sign({ data }, 'secret', { expiresIn: '1h' }) /* mengirimkan respon ke client berupa pesan */ res.json({ data, token, message: 'signin success!' }) } /* kalau perbandingan password tidak cocok, kirim pesan peringatan */ else res.json({ message: 'invalid email or password!' }) }) .catch((e) => { res.json(e) }) }) -
disaada created this gist
Sep 20, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ app.post('/signin', (req, res) => { /* * step 1 : mengambil data email dan password * yang telah diisi oleh user */ const { email, password } = req.body /* * step 2 : mengambil data user di db * berdasarkan email yang dimasukkan user * (akses ke db menggunakan ORM Sequelize) * mulai script Sequelize */ Model.user.findOne({ where: { email } }) .then((data) => { /* * data dari db didapat, bandingkan password yg diinput * dengan yg ada di db ( menggunakan bycrypt.compareSync() ) */ if (data && (bcrypt.compareSync(password, data.password))) { /* buat token menggunakan jwt.sign(data, 'secretkey', waktu_expired) */ const token = jwt.sign({ data }, 'secret', { expiresIn: '1h' }) /* mengirimkan respon ke client berupa pesan */ res.json({ data, token, message: 'signin success!' }) } /* kalau perbandingan password tidak cocok, kirim pesan peringatan */ else res.json({ message: 'invalid email or password!' }) }) .catch((e) => { res.json(e) }) /* akhir script Sequelize */ })