How can I retrieve a logged username in a Shopify app?

Topic summary

Core Issue:
A developer needs to retrieve the username of the currently logged-in user in an embedded Shopify app built with Shopify Remix and GraphQL API.

Initial Confusion:

  • First response suggested using Storefront API with customer access tokens, but this approach doesn’t apply to embedded apps.
  • The developer clarified they need information about the app user (store staff/admin), not storefront customers.

Working Solutions:

  1. App Bridge Library: Use Shopify’s App Bridge user property to access user information (documentation link provided).

  2. Online Tokens Method: Enable useOnlineTokens: true in shopify.server.js, then access user data through the session object in Remix loaders:

session.onlineAccessInfo.associated_user.id
session.onlineAccessInfo.associated_user.email

Remaining Issue:
One user reports that associated_user only returns id in their implementation, seeking guidance on retrieving additional user data beyond ID and email.

Summarized with AI on November 1. AI used: claude-sonnet-4-5-20250929.

In a Shopify app, you typically won’t have direct access to the username of the currently logged-in user due to privacy and security reasons. However, you can access the customer’s information if they are logged into their account on your store. Here’s how you can retrieve customer information including their username in a Shopify app:

  1. Using Shopify APIs: You can use the Shopify API to retrieve customer information. When a customer is logged in and interacts with your app, you can make API requests to fetch details about the currently logged-in customer.

  2. Customer Access Token: When a customer installs your app or logs in, your app can obtain a customer access token. With this token, you can make requests to the Shopify API on behalf of the customer to fetch their information, including their username if it’s available.

Here’s an example of how you might retrieve customer information including their username using Shopify’s GraphQL API in a Shopify app built on Shopify’s app framework:

query {
  customer(customerAccessToken: "CUSTOMER_ACCESS_TOKEN") {
    id
    firstName
    lastName
    email
    displayName
    ...
  }
}

Replace ‘“CUSTOMER_ACCESS_TOKEN”’ with the access token you obtained for the logged-in customer. This query will return details about the customer, including their first name, last name, email, and display name, which could be considered their username.

1 Like