Hello,
I am trying to allow anonymous login for my React Native app.
I have the loginAnonymous function implemented in my AuthProvider:
async function loginAnonymous() {
// Create an anonymous credential
const credentials = Realm.Credentials.anonymous();
try {
// Authenticate the user
const user = await app.logIn(credentials);
// `App.currentUser` updates to match the logged in user
assert(user.id === app.currentUser.id)
return user
} catch(err) {
console.error("Failed to log in", err);
}
}
When I call it, I can see that it is successful in the mongodb realm backend, however, it returns a null user/credentials.
From my reading, I assumed that a unique ID would be returned.
“Anonymous user objects have a unique ID value but no other metadata fields or configuration options.”
However, when I was reading into the Realm library, I noticed that the credentials payload for anonymous returns an empty object {}.
declare namespace Realm {
namespace Credentials {
/**
* Payload sent when authenticating using the [Anonymous Provider](https://docs.mongodb.com/realm/authentication/anonymous/).
*/
type AnonymousPayload = {};
/**
* Payload sent when authenticating using the [Email/Password Provider](https://docs.mongodb.com/realm/authentication/email-password/).
*/
type EmailPasswordPayload = {
/**
* The end-users username.
* Note: This currently has to be an email.
*/
username: string;
/**
* The end-users password.
*/
password: string;
};
I was expecting some sort of ID being returned as the user. My app currently looking at the user object to dictate wheter or not they see the login screen.
Can anyone assist?
Thanks