backend: auth bug fix

This commit is contained in:
muerwre 2018-11-30 15:15:52 +07:00
parent d932fcb287
commit c92f84c24f
7 changed files with 12 additions and 81 deletions

View file

@ -7,6 +7,8 @@ module.exports = async (req, res) => {
const user = await User.findOne({ _id: id, token });
const random_url = await generateRandomUrl();
console.log('USER', { id, token });
if (user) {
return res.send({ success: true, ...user.toObject(), id: user._id, random_url });
}

View file

@ -65,9 +65,15 @@ module.exports = async (req, res) => {
first_name, last_name, name, photo
}).save();
res.render('social/success', { title: STRINGS.OAUTH.SUCCESS_TITLE, ...user });
console.log('AUTH', auth.toObject());
res.render('social/success', { title: STRINGS.OAUTH.SUCCESS_TITLE, ...user, token: auth.token });
} else {
const created = await User.create(user, (err, result) => result.toObject());
const created = await User.create(user, (err, result) => {
if (err) console.log('ERRRRRR', err);
console.log('USER', result);
return result.toObject();
});
res.render('social/success', { title: STRINGS.OAUTH.SUCCESS_TITLE, ...user, ...created });
}

View file

@ -6,7 +6,7 @@ module.exports = async (req, res) => {
const { body, body: { id, token, force } } = req;
const owner = await User.findOne({ _id: id, token });
if (!owner) return res.send({ success: false, reason: 'Unauthorized' });
if (!owner) return res.send({ success: false, reason: 'unauthorized', id, token });
const title = parseString(body.title, 32);
const address = parseString(body.address, 32);