I know that they closed the previous question regarding this, but I am looking for a way to update the auth data as the message each time it is authenticated. This must be written when creating the user? I attach the function to create the user or should I pass the authentication token if I have a custom wallet should I pass a token or something like that? I can’t find anything in the document or I don’t know if I’m looking wrong:
first function: auth, second function create user, and the other question is how can I encrypt the private key with these same functions, could you please give me an example with the same functions.
const LoginMail = async (values: any) => {
setStateCircularProgress(true);
if (!state.authenticated) {
await Moralis.User.logIn(values.username, values.password)
.then(async function (user) {
const userMarketType = user.get("loginType");
setValuesAlertFunc(true, "Welcome to Koolinart", "success");
dispatch({
type: "USER_AUTHENTICATED",
payload: true,
});
dispatch({
type: "GET_LOGIN_TYPE",
payload: userMarketType,
});
dispatch({
type: "USER_RENDER",
payload: user,
});
})
.catch(function (error) {
// setValuesAlertFunc(true, " Invalid username/password.", "error");
const errorMessage = JSON.stringify(error);
const errorObjeto = JSON.parse(errorMessage);
setValuesAlertFunc(true, errorObjeto.message, "error");
console.log("🚀 error de login", error);
});
const ethAddress = state.userRender.attributes?.ethAddress
? state.userRender.attributes.ethAddress
: "";
await fetchTokenBalance(ethAddress);
}
setStateCircularProgress(false);
};
const SetLoginMail = async (values: any) => {
setStateCircularProgress(true);
const user = new Moralis.User();
user.set("fullname", values.fullname);
user.set("username", values.username.toLowerCase());
user.set("email", values.email);
user.set("password", values.password);
const wallet = ethers.Wallet.createRandom();
user.set("mnemonic", wallet.mnemonic.phrase);
user.set("privateKey", wallet.privateKey);
user.set("ethAddress", wallet.address.toLowerCase());
user.set("accounts", [wallet.address.toLowerCase()]);
user.set("loginType", "email");
user.set("authData", {
"moralisEth": {
"id": `${wallet.address.toLowerCase()}`,
"signature": `${wallet.privateKey}`,
"data": `Welcome to Koolinart\n\nId:${wallet.address}`
}
})
try {
await user.signUp();
setValuesAlertFunc(true, "Successful creation", "success");
// Hooray! Let them use the app now.
} catch (error) {
const errorMessage = JSON.stringify(error);
const errorObjeto = JSON.parse(errorMessage);
setValuesAlertFunc(true, errorObjeto.message, "error");
// Show the error message somewhere and let the user try again.
// alert("Error: " + error.code + " " + error.message);
}
setStateCircularProgress(false);
};