Update server/sessionStore.js
Browse files- server/sessionStore.js +38 -7
server/sessionStore.js
CHANGED
|
@@ -93,18 +93,49 @@ export const sessionStore = {
|
|
| 93 |
return s;
|
| 94 |
},
|
| 95 |
async deleteUserSession(userId, accessToken, id) {
|
|
|
|
|
|
|
| 96 |
try {
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
} catch (ex) {
|
| 99 |
-
console.
|
| 100 |
}
|
| 101 |
-
await userClient(accessToken).from('web_sessions').delete()
|
| 102 |
-
.eq('id', id).eq('user_id', userId).catch(() => {});
|
| 103 |
},
|
| 104 |
async deleteAllUserSessions(userId, accessToken) {
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
},
|
| 109 |
async _persist(uc, userId, s) {
|
| 110 |
await uc.from('web_sessions').upsert({
|
|
|
|
| 93 |
return s;
|
| 94 |
},
|
| 95 |
async deleteUserSession(userId, accessToken, id) {
|
| 96 |
+
// ① Remove the .catch() from the query chain
|
| 97 |
+
// ② Use try/catch to surface any unexpected errors
|
| 98 |
try {
|
| 99 |
+
// Remove the session from the in‑memory cache
|
| 100 |
+
userCache.get(userId)?.sessions.delete(id);
|
| 101 |
+
|
| 102 |
+
// Perform the actual DB delete
|
| 103 |
+
const { error } = await userClient(accessToken)
|
| 104 |
+
.from('web_sessions')
|
| 105 |
+
.delete()
|
| 106 |
+
.eq('id', id)
|
| 107 |
+
.eq('user_id', userId);
|
| 108 |
+
|
| 109 |
+
if (error) {
|
| 110 |
+
console.error('Supabase delete error:', error.message);
|
| 111 |
+
}
|
| 112 |
} catch (ex) {
|
| 113 |
+
console.error('Unexpected deleteUserSession error:', ex);
|
| 114 |
}
|
|
|
|
|
|
|
| 115 |
},
|
| 116 |
async deleteAllUserSessions(userId, accessToken) {
|
| 117 |
+
// Clear the in‑memory store first
|
| 118 |
+
const u = userCache.get(userId);
|
| 119 |
+
if (u) {
|
| 120 |
+
u.sessions.clear();
|
| 121 |
+
} else {
|
| 122 |
+
console.log('No user for ' + userId);
|
| 123 |
+
return null;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// Delete everything from Supabase
|
| 127 |
+
try {
|
| 128 |
+
const { error } = await userClient(accessToken)
|
| 129 |
+
.from('web_sessions')
|
| 130 |
+
.delete()
|
| 131 |
+
.eq('user_id', userId);
|
| 132 |
+
|
| 133 |
+
if (error) {
|
| 134 |
+
console.error('Supabase bulk delete error:', error.message);
|
| 135 |
+
}
|
| 136 |
+
} catch (ex) {
|
| 137 |
+
console.error('Unexpected deleteAllUserSessions error:', ex);
|
| 138 |
+
}
|
| 139 |
},
|
| 140 |
async _persist(uc, userId, s) {
|
| 141 |
await uc.from('web_sessions').upsert({
|