@textile/hub > Client > getToken
Client.getToken() method
Obtain a token per user (identity) for interacting with the remote API.
Signature:
getToken(identity: Identity, ctx?: ContextInterface): Promise<string>;
Parameters
Parameter | Type | Description |
---|---|---|
identity | Identity | A user identity to use for creating records in the database. A random identity can be created with `Client.randomIdentity(), however, it is not easy/possible to migrate identities after the fact. Please store or otherwise persist any identity information if you wish to retrieve user data later, or use an external identity provider. |
ctx | ContextInterface | Context object containing web-gRPC headers and settings. |
Returns:
Promise<string>
Example
import {Client, Identity} from '@textile/hub'
async function newToken (client: Client, user: Identity) {
// Token is added to the client connection at the same time
const token = await client.getToken(user)
return token
}