Building Authentication with passport.js Chapter 6
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user){
done(err, user)
})
});
// register a user
app.post('/users/register', (req, res) => {
const email = req.body.email;
const fullname = req.body.fullname;
const password = req.body.password;
const role = req.body.role || 'user';
const newUser = new User({
email: email,
fullname: fullname,
role: role,
password: password
})
User.createUser(newUser, function(error, user) {
if (error) {
res.status(422).json({
message: "Something went wrong. Please try again after some
time!"
});
}
res.send({ user: user })
})
})
}
Replace the contents of the script tag of AddMovie.vue with the following code:
<script>
import axios from 'axios';
export default {
data: () => ({
valid: true,
name: '',
description: '',
genre: '',
release_year: '',
nameRules: [
v => !!v || 'Movie name is required',