mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Fix invalidating auth token when device reports uninstall
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { difference } from 'lodash'
|
||||||
import * as Sequelize from 'sequelize'
|
import * as Sequelize from 'sequelize'
|
||||||
import { Database } from '../../database'
|
import { Database } from '../../database'
|
||||||
|
|
||||||
@@ -129,11 +130,25 @@ export async function deleteFamilies ({ database, familiyIds }: {
|
|||||||
|
|
||||||
// olddevice
|
// olddevice
|
||||||
if (oldDeviceAuthTokens.length > 0) {
|
if (oldDeviceAuthTokens.length > 0) {
|
||||||
await database.oldDevice.bulkCreate(
|
const knownOldDeviceAuthTokens = await database.oldDevice.findAll({
|
||||||
oldDeviceAuthTokens.map((item) => ({
|
where: {
|
||||||
deviceAuthToken: item
|
deviceAuthToken: {
|
||||||
}))
|
[Sequelize.Op.in]: oldDeviceAuthTokens
|
||||||
)
|
}
|
||||||
|
},
|
||||||
|
transaction
|
||||||
|
}).map((item) => item.deviceAuthToken)
|
||||||
|
|
||||||
|
const oldDeviceAuthTokensToAdd = difference(oldDeviceAuthTokens, knownOldDeviceAuthTokens)
|
||||||
|
|
||||||
|
if (oldDeviceAuthTokensToAdd.length > 0) {
|
||||||
|
await database.oldDevice.bulkCreate(
|
||||||
|
oldDeviceAuthTokensToAdd.map((item) => ({
|
||||||
|
deviceAuthToken: item
|
||||||
|
})),
|
||||||
|
{ transaction }
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// family
|
// family
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ export async function reportDeviceRemoved ({ database, deviceAuthToken, websocke
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (deviceEntry) {
|
if (deviceEntry) {
|
||||||
|
const currentAuthToken = deviceEntry.deviceAuthToken
|
||||||
|
|
||||||
deviceEntry.didDeviceReportUninstall = true
|
deviceEntry.didDeviceReportUninstall = true
|
||||||
deviceEntry.deviceAuthToken = generateAuthToken() // invalidiate the token
|
deviceEntry.deviceAuthToken = generateAuthToken() // invalidiate the token
|
||||||
deviceEntry.save({ transaction })
|
deviceEntry.save({ transaction })
|
||||||
@@ -51,7 +53,7 @@ export async function reportDeviceRemoved ({ database, deviceAuthToken, websocke
|
|||||||
|
|
||||||
// add to old devices
|
// add to old devices
|
||||||
await database.oldDevice.create({
|
await database.oldDevice.create({
|
||||||
deviceAuthToken: deviceEntry.deviceAuthToken
|
deviceAuthToken: currentAuthToken
|
||||||
}, {
|
}, {
|
||||||
transaction
|
transaction
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user