Compare commits
3 Commits
cada5487bf
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bb7118242b | |||
| d3a295d598 | |||
| d97abc00e2 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@chatenium/chatenium-sdk",
|
||||
"version": "1.2",
|
||||
"version": "1.2.2",
|
||||
"description": "A library for interacting with the Chatenium API",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
||||
@@ -100,21 +100,23 @@ export class SessionManager {
|
||||
* Validates and updates all sessions and returns with a new session list
|
||||
* @param sessions
|
||||
*/
|
||||
updateSessions(sessions: Session[]): Session[] {
|
||||
sessions.forEach(async session => {
|
||||
const index = sessions.indexOf(session)
|
||||
async updateSessions(sessions: Session[]): Promise<Session[]> {
|
||||
const activeSessions: Session[] = [];
|
||||
|
||||
for (const session of sessions) {
|
||||
if (!await this.validateSession(session.token)) {
|
||||
this.database.delete("sessions", session.userData.userid)
|
||||
this.keyring.delete(session.userData.userid)
|
||||
sessions.splice(index, 1)
|
||||
this.database.delete("sessions", session.userData.userid);
|
||||
this.keyring.delete(session.userData.userid);
|
||||
console.warn(`Validating session for user ${session.userData.userid} failed. Deleting session...`)
|
||||
continue;
|
||||
}
|
||||
|
||||
const updatedUserData = await this.updateUserData(session)
|
||||
this.database.set("sessions", session.userData.userid, updatedUserData)
|
||||
sessions[index] = updatedUserData
|
||||
})
|
||||
const updatedUserData = await this.updateUserData(session);
|
||||
this.database.set("sessions", session.userData.userid, JSON.stringify(updatedUserData.userData));
|
||||
activeSessions.push(updatedUserData);
|
||||
}
|
||||
|
||||
return sessions
|
||||
return activeSessions;
|
||||
}
|
||||
|
||||
private async validateSession(token: string): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user