This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This version of the application code was written for the V1 schema. | |
const val SUPPORTED_SCHEMA_VERSION = 1 | |
private val db = FirebaseFirestore.getInstance() | |
private val remoteConfig = FirebaseRemoteConfig.getInstance() | |
private val schemaMappings = mutableMapOf<String,JsonObject>() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
remoteConfig.fetchAndActivate() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service cloud.firestore { | |
match /databases/{database}/documents { | |
match /people/{person} { | |
allow write: if request.resource.data.familyName is string | |
|| request.resource.data.surname is string; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Latest security rules look for a `familyName` field instead of `surname`. This | |
// function will not therefore work. | |
fun addPerson(firstName: String, surname: String): Task<Void> { | |
val data = hashMapOf( | |
"firstName" to firstName, | |
"surname" to surname | |
) | |
return db.collection("people").document() | |
.set(data) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun addPerson(firstName: String, familyName: String): Task<Void> { | |
val data = hashMapOf( | |
"firstName" to firstName, | |
"familyName" to familyName | |
) | |
return db.collection("people").document() | |
.set(data) | |
} | |
fun getPerson(personId: String) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service cloud.firestore { | |
match /databases/{database}/documents { | |
match /users/{uid} { | |
allow write: if request.resource.data.age >= 18 | |
&& request.resource.data.email.matches('.+@.+') | |
&& request.resource.data.screenName is string | |
&& get(/databases/$(database)/documents/screenNames/$(request.resource.data.screenName)).data.uid == uid | |
&& exists(request.resource.data.company); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collection('cities').get().then(function(querySnapshot) { | |
querySnapshot.forEach(function(doc) { | |
const data = doc.data(); | |
display(data); | |
if (closeToMillion(data)) { | |
console.log(`${dat.name} is close to reaching 1 mil citizens.`); | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service cloud.firestore { | |
match /databases/{database}/documents { | |
match /cities/{city} { | |
allow write: if int(request.resource.data.population) > 0 | |
&& request.resource.data.name is string | |
&& request.resource.data.name.size() > 0 | |
&& request.resource.data.name.size() <= 32; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service cloud.firestore { | |
match /databases/{database}/documents { | |
match /cities/{city} { | |
allow write: if request.resource.data.population > 0 | |
&& request.resource.data.name is string | |
&& request.resource.data.name.size() > 0 | |
&& request.resource.data.name.size() <= 32; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class City( | |
val name: String? = null, | |
val state: String? = null, | |
val country: String? = null, | |
val isCapital: Boolean? = null, | |
val population: Long? = null, | |
val regions: List<String>? = null | |
) | |
db.collection("cities") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Specify the unique ID of the tenant to authenticate. | |
firebase.auth().tenantId = 'TENANT_ID1'; | |
// Usual Firebase sign-in logic. User will be authenticated | |
// with tenant-specific identity providers. | |
firebase.auth().signInWithEmailAndPassword(email, password) | |
.then((result) => { | |
const user = result.user; | |
// user.tenantId is set to 'TENANT_ID1'. | |
}); |