Vue.js login problem

Hi tried to install this project: https://github.com/cometchat-pro-tutorials/vue-chat-tutorial ,
but when i get to the login I get an error Failed to load resource: the server responded with a status of 401 ().

Hello @yassinebabe,

It seems like you are using v1 SDK with a v2 app. If you have created a v2 app, you need to use the v2 SDK. To migrate the sample app to be compatible with v2 apps you can follow our migration guide. I am sharing the link to the migration guide below.

Well, this didn’t help much, but I realised that if I create a cometchat project in europ it works. I am in canada, but I can’t send a message I get this error what can I do…

Hello @yassinebabe,

As seen in the error, your app does not belong to the eu region. You need to set the region to us in the init() method like this:

var appSettings = new CometChat.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion('us').build();

CometChat.init("YOUR_APP_ID", appSettings).then(
    ()=>{
        console.log("Initialized successfully");
    },error =>{
        console.log("Error in Initialization", {error});
    }
);
1 Like

Doesn’t solve the problem…

Hello @yassinebabe,

I did a test on the tutorial and everything seems to be working properly. I am attaching code snippet of init() and login() which you can use in the tutorial directly. We tested this on the latest version of JS SDK v2.0.5

INIT():

const appSettings = new CometChat.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion('eu').build();
  CometChat.init(VUE_APP_COMMETCHAT_APP_ID, appSettings).then(
    () => {
      console.log("Initialization completed successfully");
    },
    error => {
      console.log("Initialization failed with error:", error);
    }
  );

LOGIN:

CometChat.login(this.username, apiKey).then(
    () => {
      this.showSpinner = false;
      this.$router.push({
        name: "chat"
      });
    },
    error => {
      this.showSpinner = false;
      alert(
        "Whops. Something went wrong. This commonly happens when you enter a username that doesn't exist. Check the console for more information"
      );
      console.log("Login failed with error:", error.code);
    }
  );