Skip to content

Commit db2c0eb

Browse files
committed
Bug Fixes
1 parent 6d7939b commit db2c0eb

File tree

22 files changed

+6579
-3602
lines changed

22 files changed

+6579
-3602
lines changed

firestore.rules

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ service cloud.firestore {
3737
}
3838

3939
match /libraries/{library}/checkouts/{checkout} {
40-
allow get, list: if library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.CHECK_OUT || library in request.auth.token.permissions.MANAGE_CHECKOUTS || library in request.auth.token.librariesOwned);
40+
allow get: if library in request.auth.token.librariesJoined && request.auth.uid == resource.data.userID;
41+
allow list: if library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.CHECK_OUT || library in request.auth.token.permissions.MANAGE_CHECKOUTS || library in request.auth.token.librariesOwned);
4142
allow update: if library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.MANAGE_CHECKOUTS || library in request.auth.token.librariesOwned);
4243
allow create, delete: if false;
4344
}

functions/package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"node-fetch": "^3.2.10"
2424
},
2525
"devDependencies": {
26-
"firebase-functions-test": "^2.2.0",
26+
"firebase-functions-test": "^2.3.0",
2727
"jest": "^28.1.3"
2828
},
2929
"private": true

functions/src/checkouts/checkinBook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const checkinBook = functions
3131
}
3232

3333
if (
34-
!context.auth.token.permissions.CHECK_IN.includes(data.libraryID) &&
34+
!context.auth.token.permissions?.CHECK_IN?.includes(data.libraryID) &&
3535
!context.auth.token.librariesOwned.includes(data.libraryID)
3636
) {
3737
throw new functions.https.HttpsError(

functions/src/checkouts/checkoutBook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const checkoutBook = functions
3333
}
3434

3535
if (
36-
!context.auth.token.permissions.CHECK_OUT.includes(data.libraryID) &&
36+
!context.auth.token?.permissions?.CHECK_OUT?.includes(data.libraryID) &&
3737
!context.auth.token.librariesOwned.includes(data.libraryID)
3838
) {
3939
throw new functions.https.HttpsError(

functions/src/users/approveUser.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ const approveUser = functions
4141
);
4242
}
4343

44-
console.log(data, typeof data.expiration);
45-
4644
// Type Verification
4745
if (
4846
typeof data.firstName !== 'string' ||
@@ -116,12 +114,9 @@ const approveUser = functions
116114
const userClaims = user.customClaims;
117115

118116
const newLibrariesJoined = [];
119-
if (userClaims && Array.isArray(userClaims?.librariesJoined)) {
120-
newLibrariesJoined.push(userClaims.librariesJoined);
121-
newLibrariesJoined.push(data.libraryID);
122-
} else {
123-
newLibrariesJoined.push(data.libraryID);
124-
}
117+
if (userClaims && Array.isArray(userClaims?.librariesJoined))
118+
newLibrariesJoined.push(...userClaims.librariesJoined);
119+
newLibrariesJoined.push(data.libraryID);
125120

126121
getAuth()
127122
.setCustomUserClaims(data.uid, {

0 commit comments

Comments
 (0)