Users class
Users a client wrapper for interacting with the Textile Users API.
This API has the ability to:
Register new users with a User Group key and obtain a new API Token
Get and List all Threads created for/by the user in your app.
Create an inbox for the user or send message to another user's inbox.
Check, read, and delete messages in a user's inbox.
Signature:
export declare class Users extends GrpcAuthentication
Extends: GrpcAuthentication
Example 1
Initialize a the User API and list their threads.
import { Users, UserAuth } from '@textile/hub'
const example = async (auth: UserAuth) => {
const api = Users.withUserAuth(auth)
const list = api.listThreads()
return list
}
Example 2
Create a new inbox for the user
import { Users } from '@textile/hub'
// This method requires you already authenticate the Users object.
async function setupMailbox (users: Users) {
await users.setupMailbox()
}
Example 3
Send a message to a public key
import { Users, Identity, PublicKey } from "@textile/hub"
// This method requires you already authenticate the Users object.
async function example(users: Users, from: Identity, to: PublicKey, message: string) {
const encoder = new TextEncoder()
const body = encoder.encode(message)
return await users.sendMessage(from, to, body)
}
Methods
Method | Modifiers | Description |
---|---|---|
copyAuth(auth, options) | static | Copies the full scope and authentication from one API instance to this one. This will copy any existing authentication and authorization info, including:- Information created withKeyInfo and withUserAuth.- Any token generated from getToken or getTokenChallenge.- If you scoped the instance to a specific thread using withThread |
deleteInboxMessage(id) | Mark a message as read | |
deleteSentboxMessage(id) | Mark a message as read | |
getMailboxID() | Returns the mailboxID of the current user if it exists. | |
getThread(name) | Gets a users existing thread by name. | |
getToken(identity) | Obtain a token for interacting with the remote API. When your app is creating new private-key based users to interact with the API using User Group keys, you must first create a new token for each new user. Tokens do not change after you create them. | |
getTokenChallenge(publicKey, callback) | Obtain a token for interacting with the remote API. When your app is creating new private-key based users to interact with the API using User Group keys, you must first create a new token for each new user. Tokens do not change after you create them. This callback method will require you to handle challenge signing. | |
getUsage(options) | GetUsage returns current billing and usage information. | |
listInboxMessages(opts) | List the inbox of the local user | |
listSentboxMessages(opts) | List the sent messages of the local user | |
listThreads() | Lists a users existing threads. This method requires a valid user, token, and session. | |
readInboxMessage(id) | Mark a message as read | |
sendMessage(from, to, body) | A local user can author messages to remote user through their public-key | |
setToken(token) | Obtain a token for interacting with the remote API. When your app is creating new private-key based users to interact with the API using User Group keys, you must first create a new token for each new user. Tokens do not change after you create them. | |
setupMailbox() | Setup a user's inbox. This is required for each new user. An inbox must be setup by the inbox owner (keys) before messages can be sent to it. | |
watchInbox(id, callback) | watchInbox watches the inbox for new mailbox events. Returns a listener of watch connectivity states. | |
watchSentbox(id, callback) | watchSentbox watches the sentbox for new mailbox events. Returns a listener of watch connectivity states. | |
withKeyInfo(key, options) | static | Creates a new API client instance for accessing the gRPC API using key & secret based authentication. This method is recommended for admin or insecure implementations where the non-signing keys or key with secret can be embedded directly in an app. |
withThread(threadID) | Scope future API calls to a specific thread. For both Buckets and Threads, many API calls require knowledge about which thread you are making requests against. Use withThread to declare your target thread before making those API calls. | |
withUserAuth(auth, options) | static | Creates a new API client instance for accessing the gRPC API using User Group key authentication. This method is recommended for public apps where API secrets need to remain hidden from end users. |