mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-10-01 06:38:00 -05:00
Safer connection updates
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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')
|
||||
});
|
||||
|
||||
|
||||
@@ -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')
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user