Do we need to login via wallet or email to use Moralis SDK?

If so, why? Cos I’m assuming we just need to include API key in our code so that my dapp can run without asking my user/admin to login to Moralis.

I’m confused after watching these videos -> https://www.youtube.com/watch?v=jRjFn__kVJM and https://youtu.be/aYi1_moT4kI

In order to use web3api functions, you don’t have to authenticate. In particular for Moralis.Web3API.account function you would need a web3 instance enabled if you want the current address to be obtain from current web3 instance in case that you don’t provide it explicitly.

@cryptokid Thank you for your reply. But If I don’t have to authenticate, why am I getting the error “Cos I’m getting the error Error: File upload by public is disabled.

uploading files in particular is restricted to authenticated users, you can authenticate with metamask and after that to upload a file

@cryptokid is there anyway I can upload files without asking users to authenticate? Like including an API key instead? I need to allow my users to upload files without having to access their wallet. I’m trying to allow my non-blockchain literate users to use my web app without bogging them down on the intricacies of it.

The scenario here is to allow users to upload certain documents on my web app. Instead of using typical cloud storage, i’m using ipfs.

it is a way, using cloud functions, but it may not work at this right moment
you can also authenticate with a standard username and password if you want for any user

@cryptokid I really appreciate your swift replies. I’m progressing because of you. Thank you.

So, do you mean that I need to…

  1. Create a new user using the code under “Sign Up with Username” in https://docs.moralis.io/moralis-server/users/email-login
  2. Login the new user also using the code under “Log In With Username” in the tutorial in #1
  3. Upload the files to IPFS by being authenticated with the user I just created in step #1 and #2?

yes, if you follow those steps then it should work

1 Like

@cryptokid I did the below. But now I’m getting “Uncaught (in promise) Error: Invalid session token at handleError (moralis.js?_=1637580775296:25228)”

// upload image 
        $( "#upload-image" ).change( async function() {         
            var selected = $( this )[0].files.length;
            if ( ! selected ) return false;

            //Start. Implementing Moralis SDK way
            $.getScript('https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js', async function() {
                $.getScript('https://unpkg.com/moralis/dist/moralis.js', async function() {
                        
                    // connect to Moralis server
                    Moralis.initialize("o9YG2udd965.....Pd....oKPA");
                    Moralis.serverURL = "https://e8b....qaf.usemoralis.com:2053/server";
                    
                    const user = Moralis.User.logIn("qwe100", "mHCsfsdf");
            
                    // Save file input to IPFS
                    const data = $('#upload-image').get(0).files[0]
                    const file = new Moralis.File(data.name, data)
                    await file.saveIPFS();
                    
                    console.log(file.ipfs(), file.hash());
                      
                });
            });

you may need to use this syntax with await:
const user = await Moralis.User.logIn("myname", "mypass");

1 Like

@cryptokid you’re a genius! It finally worked! Thank you so much.

1 Like