ShoppingateShoppingateDevelopers
shoppinggate.app ↗
Documentation
  • What is a Mini App
  • Why Mini Apps
  • API integration
  • SDK
  • Webview
  • Mini App architecture
  • Getting started
  • Choosing your path
  • Introduction
    • Introduction
    • Sign up & login
    • Dashboard & analytics
    • Mini-Programs
    • Submit & publish a version
    • App Binding
    • Privacy Settings
    • Allowed URL
    • Users & roles
    • Introduction
    • Become a Mini-App vendor
    • API keys
    • My Mini-Apps
    • Orders
    • Webhook
    • Deep-link config
    • Introduction
    • Install & log in
    • Create a project
    • The workspace
    • Preview & upload
  • Introduction
  • Configuration
  • Lifecycle
  • Routing & query
  • Host functions
  • orderPayment
  • Permissions
  • User info
  • Introduction
  • Configuration
  • SDK
  • Lifecycle
  • Routing & query
  • Host functions
  • orderPayment
  • Permissions
  • User info
  • Web app and shell calls
  • Look and feel
  • Overview
    • Verify user
    • Create order
    • Get order
    • Update order status
    • Charge an order
    • Send a notification
  • Subscriptions
    • Create a subscription
    • List subscriptions
    • Get a subscription
    • Update a subscription
    • Reschedule next charge
    • Change plan (upgrade)
    • Cancel a subscription
  • Webhooks
Web view mini-app

User info

Your web app gets the same user info as a native Mini App, and reads it the same way: ask for the permission once, then read it every time the Mini App opens. Only the way you call it is different — the shell reads it and passes it to your web app.

When to read it

Read the user info every time your Mini App opens, not only the first time. The user can change their name, email or address in the Shoppingate app while your Mini App is closed. When they open it again, it comes back from the cache — the launch code doesn't run again, but the show event does. Reading it on show is what picks up the change.

Step
Where
Ask for the permission — once
The shell's App.onLaunch
Read the user info — every open
Your web app, when it starts and in ft.miniProgram.onShow

This is the same pattern as a native Mini App — see Native mini-app → User info.

The permission

The first time it is asked, the user allows or denies it. After that, the prompt doesn't show again:

  • Allowed — every read returns the user info, with no prompt.
  • Denied — every read returns nothing. The only way back is the settings screen, the same as in a native Mini App. Opening it needs a real tap on a native button — see Permissions → The settings screen.

How to call it

Your web app can't call getUserInfo itself, and it isn't a host function, so ft.callNativeAPI doesn't reach it. The shell reads it and sends it to your web app, through the same relay your web app uses for anything only the shell can call — see Web app and shell calls.

1. The shell asks for the permission, once
// The shell — app.js. Ask for the permission ONCE, when the Mini App launches.
// A cached Mini App reopens without running onLaunch again, so this asks one time only.
App({
  onLaunch() {
    ft.getSetting({
      success: (res) => {
        const state = res.authSetting["scope.userInfo"];

        if (state === true) return;               // already granted — nothing to ask

        if (state === false) return;              // denied before — the prompt can't show again;
                                                  // only the settings screen can turn it back on

        ft.authorize({ scope: "scope.userInfo" }); // never asked — this shows the prompt
      },
      fail: (err) => console.log("getSetting fail", err),
    });
  },
});
2. The shell reads it when your web app asks
// The shell — index.js. The relay calls this when your web app asks for "getUserInfo".
// It only READS — no prompt, no modal — so it is safe to call on every show.
const HANDLERS = {
  getUserInfo(params, reply) {
    ft.getSetting({
      success: (res) => {
        if (res.authSetting["scope.userInfo"] !== true) {
          return reply(true, null);               // not granted — no user info
        }
        ft.getUserInfo({
          success: (r) => reply(true, r.userInfo),
          fail: (err) => reply(false, err),
        });
      },
      fail: (err) => reply(false, err),
    });
  },
};
3. Your web app reads it on every open
// Your web app — read the user info when it starts, AND every time it shows again.
// askShell is the relay helper from "Web app and shell calls".
function readUserInfo() {
  askShell("getUserInfo").then(
    function (userInfo) {
      // null when the permission is not granted — show the screen without it.
      renderUser(userInfo);
    },
    function (err) {
      console.log("getUserInfo failed", err);
    }
  );
}

readUserInfo();                                   // the first open

if (window.ft && ft.miniProgram) {
  ft.miniProgram.onShow(readUserInfo);            // every time the user comes back
}

ft.miniProgram.onShow is explained in Lifecycle.

What comes back

Your web app receives the same userInfo object as a native Mini App:

{
  "id": "1234",
  "mobile": "500000000",
  "token": "example_token_value",
  "email": "[email protected]",
  "first_name": "John",
  "last_name": "Doe",
  "nickName": "",
  "avatarUrl": "",
  "gender": "0",
  "language": "en",
  "city": "",
  "province": "",
  "country": "",
  "address": {
    "latitude": "24.7136",
    "longitude": "46.6753",
    "location": "1234 Example Street, Riyadh, ABCD1234, Saudi Arabia"
  }
}

The same rules apply — nickName is always empty, gender is a string, address is an object, and a user who signed up with only a mobile number has empty name and email fields. All of it is explained on Native mini-app → User info.

token identifies the user to your backend. Send it to your backend, which verifies it with Shoppingate — see Verify user.