Implemented googleapi access token refresher

This commit is contained in:
Eclypsed
2024-02-17 00:31:11 -05:00
parent 416803af81
commit 85a17dcd89
6 changed files with 84 additions and 55 deletions

Binary file not shown.

View File

@@ -60,10 +60,10 @@ export class Connections {
static getUserConnections = (userId: string): Connection[] => {
const connectionRows = db.prepare('SELECT * FROM Connections WHERE userId = ?').all(userId) as ConnectionsTableSchema[]
const connections: Connection[] = []
connectionRows.forEach((row) => {
for (const row of connectionRows) {
const { id, service, tokens } = row
connections.push({ id, userId, service: JSON.parse(service), tokens: JSON.parse(tokens) })
})
}
return connections
}
@@ -78,4 +78,9 @@ export class Connections {
const commandInfo = db.prepare('DELETE FROM Connections WHERE id = ?').run(id)
if (commandInfo.changes === 0) throw new Error(`Connection with id: ${id} does not exist`)
}
static updateTokens = (id: string, tokens: Tokens): void => {
const commandInfo = db.prepare('UPDATE Connections SET tokens = ? WHERE id = ?').run(JSON.stringify(tokens), id)
if (commandInfo.changes === 0) throw new Error('Failed to update tokens')
}
}