Question about the JS-SDK

hello guys, I have some questions regarding the JS-Code, in the following function:
static async authenticate(options) {

  1. authenticate(options),
    when to pass a custom signing message and when to use MoralisWeb3.getSigningData() instead? In the Moralis docs and Youtube video no parameter is passed to authenticate() though.

  2. accountsLower = accounts.map(v => v.toLowerCase());
    why tolowercase?

  3. await ParseUser.logInWith(‘moralisEth’, { authData });
    Does this also work when the user doesn’t exist yet? I’m wondering why the parse method “signUp” is not used instead.

  4. what does following do?: user.setACL(new ParseACL(user));

Hey @fourtimesperday

This is really cool that you decided to take a look at the source code of Moralis JS-SDK.
It has own logic which built on Parse.

  1. You should use authenticate({signingMessage:"Hi"}) only
  2. All addresses in the Moralis Database storted in Lower Case.
  3. Signup requires provided username and password. Moralis.authenticate() automatically creates a new User in the table if it wasn’t registered before.
  4. Take a look at Role-Based Security for Other Objects docs

Hope this will help you :mage:

If you’d like to contribute to our open source Moralis JS SDK - feel free to open PRs https://github.com/MoralisWeb3/Moralis-JS-SDK

  1. [quote=“Yomoo, post:2, topic:2903”]
    You should use authenticate({signingMessage:"Hi"}) only
    [/quote]
    How come? the [docs](You cannot post a link to that host) don’t say anything about that, or?

  2. But WHY?

  3. It’s not clear, Moralis.authenticate also requires username and password.

  1. If you will not specify {signingMessage:"Hi"} it will show default Message : Moralis Authentication docs
  2. Docs
  3. Moralis.authenticate is a crypto authenticaton. Moralis.login is non-crypto
1 Like

The problem I currently see with Moralis.authenticate is that it is automatically creating an user, it doesn’t differentiate between login and sign-up. Normally each app has a separate login and sign-up button/process so I’m confused how to use that function in practice because I would expect a separate function with different callbacks for login and signup, like for example for login you would have the callback “user doesn’t exist” and then you would ask the user if he wants to create an account and so on.

Normally you login/signup with your login&password. But you can’t implement this logic with your metamask for example, right?

If you want to create a required info like email, password, username and etc you can use something like:

let user = await Moralis.authenticate();
if (!user.get("email")) {
  //redirect to user profile edit page
}
1 Like