Create User / Login
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.
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 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
});
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.
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
})
Response
{
"user":
{
"id": "b1ab-a030-fdbb",
"username": "test1",
"profileImageUrl": "",
"disablePushNotification": false,
"data": null,
"updatedAt": 1651819810137,
"createdAt": 1651819810137
}
}
Last updated