Skip to main content

Auth login authentication

getUserInfo

1. Interface Description

Function: Get user information

Interface declaration: getUserInfo(): IGetUserInfoResult

2. Input Parameters

None

3. Response

FieldTypeRequiredDescription
openIdstringRequiredWeChat openId, empty if not logged in via WeChat authorization
appIdstringRequiredWeChat appId, empty if not logged in via WeChat authorization
uidstringRequiredUser unique ID
customUserIdstringRequiredDeveloper-defined user unique id, empty if not logged in via custom authentication

4. Sample Code

import tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "xxx" });
const auth = app.auth();

exports.main = async (event, context) => {
const {
openId, // WeChat openId, empty if not logged in via WeChat authorization
appId, // WeChat appId, empty if not logged in via WeChat authorization
uid, // User unique ID
customUserId, // Developer-defined user unique id, empty if not logged in via custom authentication
} = auth.getUserInfo();
console.log(openId, appId, uid, customUserId);
};

getEndUserInfo

1. Interface Description

Function: Get user information

Interface declaration: getEndUserInfo(uid?: string, opts?: ICustomReqOpts): Promise<IGetEndUserInfoResult>

Note

This interface is supported since Node SDK version 2.2.5.

2. Input Parameters

FieldTypeRequiredDescription
uidstringNoCloudBase user identity. If not passed, user information will be read from environment variables.
optsObjectNoCustom request configuration

3. Response

FieldTypeRequiredDescription
userInfoEndUserInfoYesCloudBase user information
requestIdstringNoRequest unique identifier

EndUserInfo:

FieldTypeDescription
openIdstringWeChat openId, empty if not logged in via WeChat authorization
appIdstringWeChat appId, empty if not logged in via WeChat authorization
uidstringUser unique ID
customUserIdstringDeveloper-defined user unique id, empty if not logged in via custom authentication
envNamestringCloudBase environment name
nickNamestringNickname
emailstringUser login email
usernamestringUser login username
hasPasswordbooleanWhether the user has set a password
gender"MALE" \| "FEMALE" \| "UNKNOWN"CloudBase login username
countrystringCountry (geographical location)
provincestringProvince (geographical location)
citystringCity (geographical location)
avatarUrlstringUser avatar URL
qqMiniOpenIdstringIdentifier of the qq Mini Program bound to the user

4. Sample Code

import tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "xxx" });
const auth = app.auth();

exports.main = async (event, context) => {
try {
const { userInfo } = await auth.getEndUserInfo("your user uuid");
console.log(userInfo);
} catch (error) {
console.log(error.message);
}
};

queryUserInfo

1. Interface Description

Function: Get user information

Interface declaration: queryUserInfo(query: IUserInfoQuery, opts?: ICustomReqOpts): Promise<any>

Note

This interface is supported since Node SDK version 2.6.1.

2. Input Parameters

FieldTypeRequiredDescription
queryIUserInfoQueryNoCloudBase user identity.
optsObjectNoCustom request configuration

IUserInfoQuery

FieldTypeRequiredDescription
platformstringNoLogin type. Supported values: PHONE, USERNAME, EMAIL, CUSTOM
platformIdstringNoLogin identifier corresponding to platform: phone number, username, email, or custom login ID
uidstringNoUser unique ID. If specified, this field takes precedence in the search

3. Response

FieldTypeRequiredDescription
userInfoEndUserInfoYesCloudBase user information
requestIdstringNoRequest unique identifier

EndUserInfo:

FieldTypeDescription
openIdstringWeChat openId, empty if not logged in via WeChat authorization
appIdstringWeChat appId, empty if not logged in via WeChat authorization
uidstringUser unique ID
customUserIdstringDeveloper-defined user unique id, empty if not logged in via custom authentication
envNamestringCloudBase environment name
nickNamestringNickname
emailstringUser login email
usernamestringUser login username
hasPasswordbooleanWhether the user has set a password
gender"MALE" \| "FEMALE" \| "UNKNOWN"CloudBase login username
countrystringCountry (geographical location)
provincestringProvince (geographical location)
citystringCity (geographical location)
avatarUrlstringUser avatar URL
qqMiniOpenIdstringIdentifier of the qq Mini Program bound to the user

4. Sample Code

import tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "xxx" });
const auth = app.auth();

exports.main = async (event, context) => {
try {
const { userInfo } = await auth.getEndUserInfo("your user uuid");
console.log(userInfo);
} catch (error) {
console.log(error.message);
}
};

getClientIP

1. Interface Description

Function: Get client IP

Interface declaration: getClientIP(): string

2. Input Parameters

None

3. Response

FieldTypeRequiredDescription
-stringRequiredClient IP

4. Sample Code

import tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "xxx" });
const auth = app.auth();

exports.main = async (event, context) => {
const ip = auth.getClientIP(); // string
console.log(ip);
};

createTicket

1. Interface Description

Function: Get the login credentials ticket for custom login

Interface declaration: createTicket: (customUserId: string, options?: ICreateTicketOpts) => string

2. Input Parameters

FieldTypeRequiredDescription
customUserIdstringRequiredDeveloper-defined user unique id
ICreateTicketOptsstringRequiredWeChat appId, empty if not logged in via WeChat authorization

ICreateTicketOpts

FieldTypeRequiredDescription
refreshnumberNoaccess_token refresh time
expirenumberNoaccess_token expiration time

3. Response

FieldTypeRequiredDescription
-stringRequiredCustom login credential ticket

4. Sample Code

import tcb from "@cloudbase/node-sdk";
const app = tcb.init({
env: "xxx",
credentials: require("/path/to/your/tcb_custom_login.json"),
});

const auth = app.auth();

const customUserId = "123456"; // Developer-defined user unique id

const ticket = auth.createTicket(customUserId, {
refresh: 3600 * 1000, // refresh time for access_token
});

console.log(ticket);