Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ yarn-error.log*
*.cache
.firebase/**
firebase.json
credentials.json
firebase-debug.log

.env*
6 changes: 6 additions & 0 deletions firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,11 @@ service cloud.firestore {
allow write: if isSignedIn() && isStaff();
}

// anyone can read users database to validate accounts
// TODO: make this private
match /users/{document=**} {
allow read: if isSignedIn()
}

}
}
18 changes: 17 additions & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@ const router = new Router({
beforeEnter(to, from, next): void {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
next("/home");
firebase
.firestore()
.collection("users")
.doc(user?.uid)
.get()
.then((doc) => {
if (doc.exists) {
next("/home");
} else {
console.warn("Invalid permissions");
firebase.auth().signOut();
next();
}
})
.catch((err) => {
console.error(`Something went wrong: ${err}`);
});
} else {
next();
}
Expand Down