Skip to content

Commit ffc6f6a

Browse files
authored
Revert "fix(common): APPEX-279 delete all store users on uninstall"
1 parent b2916f7 commit ffc6f6a

File tree

4 files changed

+5
-42
lines changed

4 files changed

+5
-42
lines changed

lib/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ export function decodePayload(encodedContext: string) {
8484
return jwt.verify(encodedContext, JWT_KEY);
8585
}
8686

87-
// Removes store and storeUsers on uninstall
87+
// Removes store and storeUser on uninstall
8888
export async function removeDataStore(session: SessionProps) {
8989
await db.deleteStore(session);
90-
await db.deleteStoreUsers(session);
90+
await db.deleteUser(session);
9191
}
9292

9393
// Removes users from app - getSession() for user will fail after user is removed

lib/dbs/firebase.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
import { initializeApp } from 'firebase/app';
2-
import {
3-
collection,
4-
deleteDoc,
5-
doc,
6-
getDoc,
7-
getDocs,
8-
getFirestore,
9-
query,
10-
setDoc,
11-
updateDoc,
12-
where,
13-
writeBatch,
14-
} from 'firebase/firestore';
2+
import { deleteDoc, doc, getDoc, getFirestore, setDoc, updateDoc } from 'firebase/firestore';
153
import { SessionProps, UserData } from '../../types';
164

175
// Firebase config and initialization
@@ -103,20 +91,6 @@ export async function deleteUser({ context, user, sub }: SessionProps) {
10391
await deleteDoc(ref);
10492
}
10593

106-
export async function deleteStoreUsers({ context, sub }: SessionProps) {
107-
const contextString = context ?? sub;
108-
const storeHash = contextString?.split('/')[1] || '';
109-
const storeUsersRef = query(collection(db, 'storeUsers'), where('storeHash', '==', storeHash));
110-
const storeUsers = await getDocs(storeUsersRef);
111-
const batch = writeBatch(db);
112-
113-
storeUsers.docs.forEach(doc => {
114-
batch.delete(doc.ref);
115-
});
116-
117-
await batch.commit();
118-
}
119-
12094
export async function hasStoreUser(storeHash: string, userId: string) {
12195
if (!storeHash || !userId) return false;
12296

@@ -133,9 +107,7 @@ export async function getStoreToken(storeHash: string) {
133107
return storeDoc.data()?.accessToken ?? null;
134108
}
135109

136-
export async function deleteStore({ context, sub }: SessionProps) {
137-
const contextString = context ?? sub;
138-
const storeHash = contextString?.split('/')[1] || '';
110+
export async function deleteStore({ store_hash: storeHash }: SessionProps) {
139111
const ref = doc(db, 'store', storeHash);
140112

141113
await deleteDoc(ref);

lib/dbs/mysql.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ export async function deleteUser({ context, user, sub }: SessionProps) {
7171
await query('DELETE FROM storeUsers WHERE userId = ? AND storeHash = ?', values);
7272
}
7373

74-
export async function deleteStoreUsers({ context, sub }: SessionProps) {
75-
const contextString = context ?? sub;
76-
const storeHash = contextString?.split('/')[1] || '';
77-
await query('DELETE FROM storeUsers WHERE storeHash = ?', storeHash);
78-
}
79-
8074
export async function hasStoreUser(storeHash: string, userId: string) {
8175
if (!storeHash || !userId) return false;
8276

@@ -94,8 +88,6 @@ export async function getStoreToken(storeHash: string) {
9488
return results.length ? results[0].accessToken : null;
9589
}
9690

97-
export async function deleteStore({ context, sub }: SessionProps) {
98-
const contextString = context ?? sub;
99-
const storeHash = contextString?.split('/')[1] || '';
91+
export async function deleteStore({ store_hash: storeHash }: SessionProps) {
10092
await query('DELETE FROM stores WHERE storeHash = ?', storeHash);
10193
}

types/db.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ export interface Db {
2020
getStoreToken(storeId: string): string | null;
2121
deleteStore(session: SessionProps): Promise<void>;
2222
deleteUser(session: SessionProps): Promise<void>;
23-
deleteStoreUsers(session: SessionProps): Promise<void>;
2423
}

0 commit comments

Comments
 (0)