All Products
Search
Document Center

SuperApp:Associate a user

Last Updated:Jun 04, 2026

After integrating a WindVane or uni-app miniapp container into your native app, associate the logged-in user with the container at runtime.

The miniapp container uses the userId to support the following features:

  1. Device authorization checks

  2. Automatic cookie clearing for WindVane miniapps when the SDK detects an account switch

  3. Data reporting (Page Views (PV) and Unique Visitors (UV)) — requires the reporting plugin

  4. Whitelist-based canary release on the open application platform

Associate a user

Register IUserInfoService with ServiceManager to provide the container with the current user's identity. Return a UserInfo object with the userId set when a user is logged in, or null when no user is logged in. The userId must uniquely identify the user within your app.

ServiceManager.getInstance().registerService(IUserInfoService.class.getName(), new IUserInfoService() {
    @Override
    public UserInfo getUserInfo() {
        // Returns UserInfo based on the login status. Returns null if no user is logged in.
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId(userId);
        return userInfo;
    }
});

Check device authorization

Call getUserInfo() to retrieve the current user's userId, then pass it to AuthorizationManagement.isAuthorized() to check whether the device is authorized.

private boolean isAuthorized() {
    IUserInfoService userInfoService = ServiceManager.getInstance()
        .getService(IUserInfoService.class.getName());

    // ...

    UserInfo userInfo = userInfoService.getUserInfo();

    // ...

    return AuthorizationManagement
        .getInstance(mContext)
        .isAuthorized(innerScope, userInfo.getUserId(), appId);
}

Clear cookies

The SDK automatically calls getUserInfo() to detect account switches and clear cookies for WindVane miniapps. The following shows a typical implementation:

private void clearMiniAppCookies(...) {
    IUserInfoService userInfoService = ServiceManager.getInstance()
        .getService(IUserInfoService.class.getName());

    // ...

    UserInfo userInfo = userInfoService.getUserInfo();

    // ...

    if (isDifferentUser(userInfo.getUserId())) {
        clearCookie();
    }
}

Report data

Call getUserInfo() to retrieve the current user's userId and pass it to the reporting function. This enables Page View (PV) and Unique Visitor (UV) tracking per user.

private void reportData(...) {
    IUserInfoService userInfoService = ServiceManager.getInstance()
        .getService(IUserInfoService.class.getName());

    // ...

    UserInfo userInfo = userInfoService.getUserInfo();

    // ...

    report(userInfo.getUserId());
}