Authentication

This guide will explain in-depth ChatCamp authentication workflow.

The authentication is the first step in the chat integration into your Javascript application. ChatCamp supports types of authentications: client-side and server-side. Both are discussed in detail below.

Initializing the App

To start using chat SDK into your Javascript application, you need to initialize ChatCamp with the APP_ID. This APP_ID can be copied from the ChatCamp Dashboard.

var cc = new ChatCamp({
  appId: APP_ID
})

๐Ÿ“˜

Tip:

Note: new ChatCamp() should be called only once across the entire application

Connecting with User ID

The easiest way to connect a user to chat is with the help of a user ID. If the user ID doesn't exist in ChatCamp database then a new user account is automatically created. This is purely a client side integration as there is no call to your server involved in this implementation. The user ID can be any unique string from your user database such as UID or username or email id.

cc.connect(USER_ID, function(error, user) {
  if(errror === null){
	console.log("Connected to ChatCamp")
  }
})

Connecting with Access Token

A more secure way is to create user via ChatCamp API with an access token. This access token would then be required while connecting to ChatCamp in Javascript application. This type of authentication requires server-side integration as well.

At a high level, there are three main steps in this authentication type:

  • Create a user with an access token via ChatCamp API. This implementation needs to be done on your server side.
  • Save the access token in your database.
  • Retrieve the access token from your server in your Javascript application and then use it while connecting to ChatCamp.
cc.connect(USER_ID, ACCESS_TOKEN,function(error, user) {
  if(errror === null){
	console.log("Connected to ChatCamp")
  }
})

Disconnecting from Chat

A user needs to disconnect from ChatCamp Cloud if they do not wish to receive chat related data. It can be used when the user is logging out of your app.

cc.disconnect(function(){
	console.log("User succefully disconnected")
});