User Permissions
$w.auth.getUserInfo
$w.auth.getUserInfo(): Promise<CurrentUserInfo>
Feature Description
Get Currently Logged-in User Information
Response Parameters
CurrentUserInfo
Property | Type | Description |
---|---|---|
name | string | Username |
nickName | string | Nickname |
avatarUrl | string | User avatar |
type | number | Type. 0: internal user; 1: external user; 2: anonymous user |
string | ||
phone | string | Phone number |
relatedRoles | array | The roles associated with the user. Specific fields are explained below. |
openId | string | WeChat OpenID/Enterprise WeChat OpenID |
unionId | string | WeChat unionId/Enterprise WeChat unionId |
userId | string | WeDa user id |
mainOrg | object | Primary department |
orgs | array | Concurrent departments |
userType | string | User login status. anonymousUser: Not logged in (anonymous user); externalUser: Logged in (external user) |
userDesc | string | User description |
object.relatedRoles[i] property:
Property | Type | Description |
---|---|---|
id | string | role id |
envId | string | Environment ID |
name | string | role name |
roleIdentity | string | role identity |
object.mainOrg property:
Property | Type | Description |
---|---|---|
id | string | primary department id |
name | string | Primary Department Name |
object.orgs[i] property:
Property | Type | Description |
---|---|---|
id | string | concurrent department id |
name | string | Concurrent Department Name |
Example
const userInfo = await $w.auth.getUserInfo();
console.log('$w.auth.getUserInfo:', userInfo);
console.log('$w.auth.currentUser:', $w.auth.currentUser);
/**
* {
* name: "xxx",
* avatarUrl: "xxx",
* openId: "xxx",
* unionId: "xxx",
* relatedRoles: [{envId: "lowcode-xxx", id: "xxx",name: "xxx", roleIdentity: "xxx"}],
* type: 1,
* phone: "xxx",
* email: "",
* userId: "xxx",
* mainOrg: {id: "xxx", name: "xxx"},
* orgs: [{id: "xxx", name: "xxx"}],
* userType: "anonymousUser"
* userDesc: "xxx"
* }
* /
$w.auth.currentUser
Feature Description
User Information Reference
Properties
The
$w.auth.currentUserand
$w.auth.getUserInfohave identical output parameters. Refer to the output parameters of
$w.auth.getUserInfo`.
Example
console.log('$w.auth.currentUser:', $w.auth.currentUser);
/**
* {
* name: "xxx",
* openId: "xxx",
* relatedRoles: [{envId: "lowcode-xxx", id: "xxx",name: "xxx", roleIdentity: "xxx"}],
* type: 1,
* phone: "xxx",
* email: "",
* userId: "xxx",
* mainOrg: {id: "xxx", name: "xxx"},
* orgs: [{id: "xxx", name: "xxx"}]
* }
* /
$w.auth.signOut
Feature Description
User Logout
Input Parameters
options: object
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
isRefresh | boolean | false | No | Whether to refresh the page after exiting |
Example
$w.auth?.signOut?.({ isRefresh: true });
// Setting isRefresh = true is equivalent to performing the following operations
$w.auth?.signOut?.();
setTimeout(() => {
// On the web side, refreshing the current page will automatically redirect to the default login page.
window.location.reload();
// On the Mini Program side, after logging out, you need to restart the mini program using the following method. Method reference: https://developers.weixin.qq.com/miniprogram/dev/api/navigate/wx.restartMiniProgram.html
wx.restartMiniProgram({
path: "Replace with your own page path",
});
}, 1000);
$w.auth.loginScope
Feature Description
Get User Login Permission Scope
Response Parameters
Promise<anonymous | undefined>
Value | Description |
---|---|
anonymous | Anonymous user |
undefined | Non-anonymous user |
Example
try {
const scope = await $w.auth?.loginScope?.();
} catch (e) {
// Not logged in
}
/**
* anonymous: The current state is an anonymous user. When login access is enabled, it can be considered that the user is not logged in.
* undefined: The current state is a non-anonymous user. When login access is enabled, it can be considered that the user is logged in.
*/