Safer connection updates

This commit is contained in:
Jonathan Barrow
2022-07-15 20:28:42 -04:00
parent 005e0c1e94
commit da9b2f66fe
3 changed files with 10 additions and 27 deletions

View File

@@ -177,7 +177,6 @@ function getServerByTitleId(titleId, accessMode) {
}
async function addUserConnection(pnid, data, type) {
// Add more connections later?
if (type === 'discord') {
return await addUserConnectionDiscord(pnid, data);
}
@@ -192,16 +191,11 @@ async function addUserConnectionDiscord(pnid, data) {
};
}
// Support older documents
await PNID.updateOne({
pid: pnid.get('pid')
}, {
await PNID.updateOne({ pid: pnid.get('pid') }, {
$set: {
connections: {
discord: data
}
'connections.discord': data
}
}, { upsert: true });
});
return {
app: 'api',
@@ -217,20 +211,13 @@ async function removeUserConnection(pnid, type) {
}
async function removeUserConnectionDiscord(pnid) {
// Support older documents
await PNID.updateOne({
pid: pnid.get('pid')
}, {
await PNID.updateOne({ pid: pnid.get('pid') }, {
$set: {
connections: {
discord: {
id: '',
access_token: '',
refresh_token: ''
}
}
'connections.discord.id': '',
'connections.discord.access_token': '',
'connections.discord.refresh_token': ''
}
}, { upsert: true });
});
return {
app: 'api',

View File

@@ -296,9 +296,7 @@ router.post('/', async (request, response) => {
// NN with a NNID will always use the NNID PID
// even if the provided NEX PID is different
// To fix this we make them the same PID
await NEXAccount.updateOne({
pid: newNEXAccount.get('pid')
}, {
await NEXAccount.updateOne({ pid: newNEXAccount.get('pid') }, {
owning_pid: newNEXAccount.get('pid')
});

View File

@@ -134,9 +134,7 @@ router.post('/', ratelimit, deviceCertificateMiddleware, async (request, respons
// NN with a NNID will always use the NNID PID
// even if the provided NEX PID is different
// To fix this we make them the same PID
await NEXAccount.updateOne({
pid: newNEXAccount.get('pid')
}, {
await NEXAccount.updateOne({ pid: newNEXAccount.get('pid') }, {
owning_pid: newNEXAccount.get('pid')
});