Are there any alternatives? I’ve tried a few packages for popups and none of them seem to work. I’m just needing a way to alert a message after a Post request.
You mean a pop up in a terminal???
no, on the client side
There are no node on the client side. Clients have only browser. And all of them support alerts.
Show your code.
Yes I know, I’m unsure how to add an alert on the client side after a new email and password is added to my database. I have it set to refresh the page and then I’d like an alert() letting the user know the account was created.
const express = require('express');
const bcrypt = require('bcryptjs');
const router = express.Router();
//User model
const User = require('../models/User');
router.get('/', (req, res) => res.render('index'));
router.post('/dashboard', (req, res) => {
const {email, password} = req.body;
let errors = [];
// Checks required fields to see if they are empty
if(!email || !password){
}else{
// This is where we will check to see if the username and password already exists in the database
//This creates a new account
const newUser = new User({
email,
password
});
// Hash Password
bcrypt.genSalt(10, (err, salt) => bcrypt.hash(newUser.password, salt, (err, hash) => {
if(err) throw err;
// set pass to hash
newUser.password = hash;
newUser.save()
.then(user =>{
// We also need to add a display a message here after the refresh that the user can now login
res.redirect('back');
})
.catch(err => console.log(err));
}))
}
});
module.exports = router;
Show the front end part of your code - that’s where you call alert.
do you mean the files in my views?
Maybe this will give you some ideas: https://stackoverflow.com/questions/12442716/res-redirectback-with-parameters
You can get a return value from the post request done on the client side too, the return value can be a res.json on the server side that you generate after authentication
Option b, look at the 2files in this link