Thanks again for your answer. It’s ok, mine was just curiosity, for what I have to do I don’t need to trace the id of the device.
I was completing my custom authentication function, but I noticed a small problem. To better clarify my situation I placed part of my custom function:
exports = async function(loginPayload) {
// Get a handle for the app.users collection
const users = context.services
.get("mongodb-atlas")
.db("magika_db")
.collection("users");
//console.log(loginPayload);
const username = loginPayload.toString();
const user = await users.findOne( {"userData.username": username} );
if (user) {
// If the user document exists, return its unique ID
return user._id.toString();
} else {
// If the user document does not exist, create it and then return its unique ID
const newDocument = {
"userData": {
"username": username,
"email": ""
},
"collection": [{
"name": "",
"goldIncrase": 5
}]
};
const result = await users.insertOne(newDocument);
return result.insertedId.toString();
}
};
When I call the authentication function via https://realm.mongodb.com/api/client/v2.0/app/myapp-abcde/auth/providers/custom-function/login I get “access_token”, “refresh_token”, “user_id” and “device_id”. I thought that “user_id” was the id that returns the function (so the unique id of the document where the function finds the controlled username), but I noticed that this is not the case. So “user_id” is a unique id created by authentication to authenticate the user?
If I need to receive the return value of the custom authentication function as an answer (in addition to the authentication success values), how can I do it?