Fix issue with login not adding details to user database

This commit is contained in:
2017-10-13 19:47:47 +01:00
parent 681dd80d3b
commit 1341258c32
3 changed files with 55 additions and 38 deletions

View File

@@ -8,24 +8,32 @@ const route = function (db) {
});
router.get('/:uid', function(req, res, next) {
const uid = req.params.uid;
const userRef = db.ref(`/users/${uid}`);
userRef.set({
approved: true,
});
admin.auth().createCustomToken(uid, {
approved: true,
}).then(function(customToken) {
return res.json({
success: true,
token: customToken,
admin.auth().getUser(uid)
.then(function() {
const userRef = db.ref(`/users/${uid}`);
userRef.set({
approved: true,
});
admin.auth().createCustomToken(uid, {
approved: true,
}).then(function(customToken) {
return res.json({
success: true,
token: customToken,
});
}).catch(function(err) {
console.error('Error creating custom token', err);
return res.status(500).json({
success: false,
error: err,
});
});
}).catch(function(err) {
return res.json({
success: false,
error: err,
});
});
}).catch(function(err) {
console.error('Error creating custom token', err);
return res.status(500).json({
success: false,
error: err,
});
});
});
return router;
}

View File

@@ -24,31 +24,38 @@ const route = function(db) {
});
}
const valid = password === s.val();
const userRef = db.ref(`users/${uid}`)
.set({
isAdmin: false,
isAnonymous: true,
approved: valid,
});
if (valid) {
admin.auth().createCustomToken(uid, {
approved: true,
}).then(function(customToken) {
admin.auth().getUser(uid).then(function() {
const userRef = db.ref(`users/${uid}`)
.set({
isAdmin: false,
isAnonymous: true,
approved: valid,
});
if (valid) {
admin.auth().createCustomToken(uid, {
approved: true,
}).then(function(customToken) {
return res.json({
valid: true,
token: customToken,
});
}).catch(function(err) {
console.error('Error creating custom token', err);
return res.status(500).json({
error: 'Internal server error',
});
});
} else {
return res.json({
valid: true,
token: customToken,
valid: false,
});
}).catch(function(err) {
console.error('Error creating custom token', err);
return res.status(500).json({
error: 'Internal server error',
});
});
} else {
}
}).catch(function(err) {
return res.json({
valid: false,
error: err,
});
}
});
});
});