Klat
  • TalkPlus SDK
  • Android
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • Viewing Channel LIst
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
    • What's New
  • iOS
    • Getting Started
    • Callback
    • User
      • Create / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
    • What's New
  • Unity
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
  • JavaScript
    • Getting Started
    • Realtime Event
    • Pagination
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification (FCM)
    • Sample Application
    • What's New
  • Flutter
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification (FCM)
  • REST API
    • Getting Started
    • API
      • Users
        • Create User
        • Login (using login token)
        • View User
        • Update User
        • Activate / Deactivate
        • Enable / Disable Push Notification
        • Delete User
        • View Users
        • View Channels
        • Block / Unblock
      • Channel
        • Create Channel
        • View Channel
        • Update Channel
        • Delete Channel
        • View Channel List
        • Manage Channel Members
        • Messaging
        • Hide / Show Channel
        • Channel Freeze / Unfreeze
        • Transfer Channel Ownership
        • Channel Push Notification Settings
      • Bot
        • Create Bot
        • View Bot List
        • View Bot
        • Update Bot
        • Delete Bot
        • View Joined Channel List
        • Messaging
        • Join / Leave Channel
    • Push Notification
    • Rate Limit
  • MISC
    • Webhooks
    • SDK Rate Limit
    • Error Code
    • FAQ
      • Function
      • Spec
Powered by GitBook
On this page
  • 1. Login Check
  • 2. Anonymous User
  • 3. Login Using Token
  1. JavaScript
  2. User

Create User / Login

PreviousUserNextUpdate User Information

Last updated 6 months ago

TalkPlus supports anonymous and token-based login. In order to use token-based login, you must call /api/users/create and /api/users/login from the REST API endpoints to create user and retrieve user’s login token.

If you need translation feature, see below.

Message translation feature is provided through Google Cloud Translation. To use this feature, register an appropriate Google Cloud Service Account Key on our dashboard.

  • To enable message translation, provide the language code (ISO-639) in translationTargetLanguage parameter when logging in.

  • Supported languages (ISO-639) can be found .

  • 'translations' field in message object contains translated texts. Use language code as key to retrieve the text.

1. Login Check

You can check whether current session is logged in or not.

const isLoggedIn = client.isLoggedIn();

console.log(isLoggedIn);  // true or false

2. Anonymous User

You need a unique user ID and a username to login anonymously.

You need to allow Anonymous User login option under App Settings in our dashboard to use this feature.

You can enter up to 5 key-value pairs in data field. The maximum size of key is 128 characters and the maximum size of value is 1024 characters. Both key and value must be strings.

// you can specify profile image URL
await client.loginAnonymous({
    userId: 'user-123', // unique userId
    username: 'user-123', // username, max char length: 128
    profileImageUrl: 'http://myimage.net/123.jpg',
    data: {
      metadataKey: "metadataValue"
    },
    translationTargetLanguage: 'ko', // optional
});
<input type="file" onchange="uploadFile(this)" >

<script>
    async function uploadFile(input) {
        // upload profile image file
        await client.loginAnonymous({
            userId: 'user-123', // unique userId
            username: 'user-123', // username, max char length: 128
            image: input.files[0], // maximum file upload size is 15MB
            data: {
              metadataKey: "metadataValue"
            },
            translationTargetLanguage: 'ko', // optional
        });
    }
</script>

Response

{
    "user":
    {
        "id": "b1ab-a030-fdbb",
        "username": "test1",
        "profileImageUrl": "",
        "disablePushNotification": false,
        "data": null,
        "updatedAt": 1651819810137,
        "createdAt": 1651819810137
    }
}

3. Login Using Token

You need a unique user ID, a username and a login token to login.

Call /api/users/create and /api/users/login from our REST API endpoints to obtain a login token.

You can enter up to 5 key-value pairs in data field. The maximum size of key is 128 characters and the maximum size of value is 1024 characters. Both key and value must be strings.

await client.loginWithToken({
    userId: 'user-123', // unique userId
    username: 'user-123', // username, max char length: 128
    loginToken: 'user_login_token', // login token issued by admin REST API
    profileImageUrl: 'http://myimage.net/123.jpg',
    data: {
      metadataKey: "metadataValue"
    },
    translationTargetLanguage: 'ko', // optional
})
<input type="file" onchange="uploadFile(this)" >

<script>
    async function uploadFile(input) {
        // upload profile image file
        await client.loginWithToken({
            userId: 'user-123', // unique userId
            username: 'user-123', // username, max char length: 128
            loginToken: 'user_login_token', // login token issued by admin REST API
            image: input.files[0], // maximum file upload size is 15MB
            data: {
              metadataKey: "metadata"
            },
            translationTargetLanguage: 'ko', // optional
        });
    }
</script>

Response

{
    "user":
    {
        "id": "b1ab-a030-fdbb",
        "username": "test1",
        "profileImageUrl": "",
        "disablePushNotification": false,
        "data": null,
        "updatedAt": 1651819810137,
        "createdAt": 1651819810137
    }
}
here