jamescoonce / expressapiblog Goto Github PK
View Code? Open in Web Editor NEWThis is an example Expres Blog API
This is an example Expres Blog API
in post controller in update part code bellow is not needed:
if (!req.body.post.title || !req.body.post.content) { res.status(403).end(); }
or it should be && and not ||
The module body-parser is never used.
import User from '../models/user';
import bodyParser from 'body-parser';
import passport from 'passport';
const AuthController = {};
import jwt from 'jsonwebtoken';
import { generateToken, respond } from '../middleware/authMiddleware';
AuthController.register = async (req, res) => {
try{
User.register(new User({ username: req.body.email,
firstName: req.body.firstName,
lastName: req.body.lastName,
}), req.body.password, function(err, account) {
if (err) {
return res.status(500).send('An error occurred: ' + err);
}
passport.authenticate(
'local', {
session: false
})(req, res, () => {
res.status(200).send('Successfully created new account');
});
});
}
catch(err){
return res.status(500).send('An error occurred: ' + err);
}
};
AuthController.login = async (req, res, next) => {
try {
if (!req.body.email || !req.body.password) {
return res.status(400).json({
message: 'Something is not right with your input'
});
}
passport.authenticate('local', {session: false}, (err, user, info) => {
if (err || !user) {
return res.status(400).json({
message: 'Something is not right',
user : user
});
}
req.login(user, {session: false}, (err) => {
if (err) {
res.send(err);
}
// generate a signed son web token with the contents of user object and return it in the response
const token = jwt.sign({ id: user.id, email: user.username}, 'ILovePokemon');
return res.json({user: user.username, token});
});
})(req, res);
}
catch(err){
console.log(err);
}
};
I saw the following -
WARNING: The `useMongoClient` option is no longer necessary in mongoose 5.x, please remove it.
While this is not pressing but still an issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.