Hello,
I would like to know what is the best solution to manage authenticate user.
We can get the authenticate user id with
user = useUser()
console.log(user.id)
Has it is not part of a collection i can not create to-one relationship
for example here I can only create a to-many relationship (userId being the foreign key) :
export class Picture extends Realm.Object {
static schema = {
name: "Picture",
properties: {
_id: { type: "objectId", default: () => new Realm.BSON.ObjectId() },
pictureUrl: { type: "string", default: () => "https://img.freepik.com/premium-vector/cute-australian-shepherd-dog-avatar-cartoon_357749-252.jpg?w=740" },
pictureBlob: "data?",
userId: "string"
},
primaryKey: "_id",
};
}
My workaround would be to create a user collection with the to-one relationship with Picture like :
export class User extends Realm.Object {
static schema = {
name: "User",
properties: {
_id: { type: "objectId",},
name: "string?",
picture: "Picture?"
},
primaryKey: "_id",
};
}
and i remove the UserId from my Picture shema
Then
i will create the user object when the user logs in
Is it the right way to do?
Is there any other way to manage users information and create to-one relationship?