Which is the best approach for an app with multiple users using Room database?

127 views Asked by At

I'm developing an app (Android, Kotlin) that allows the user to register different documents with specific information in Room database. I'll implement in the app to only be able to display the files registered if the user is logged in.
It concerns me because if a device is shared, everything you need is to log in to access another user data, which is totally not cool.
I'm using room database and firebase for authentication. I was wondering if every time the user add a new file to room database and it includes the auth.currentUser!!.uid and also every query request for the database, would it be alright? For example:

@Entity(tableName = "example")
data class Model(
    @PrimaryKey
    var id: Int? = null,
    var title: String? = null,
    val userId: String = Firebase.auth.currentUser!!.uid
)

And every request for the database automatically uses the current user to request data from Room. Would it be a bad approach for a case like that? If it is not, how could I separate properly the data from different users in the same database?
Thanks for your help

0

There are 0 answers