App reviews, troubleshooting, and recommendations
Hi,
I need to retrieve the username of the currently logged in user for my shopify app.
App is based on shopify remix and queryAPI.
Is there such a possibility?
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:
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.
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.
I forgot to mention that the application I am creating is of the embeded type. The solution you provided is directed to Storefront Api.
There is something similar for embeded apps?
I'm referring to the information of the user who is currently using the app.
Lets say you are working on shopify app it has an embedded shopify instance called ShopifyGlobal with variable name shopify it consist of a property called user. You can find further about this here.
https://shopify.dev/docs/api/app-bridge-library/apis/user
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024