App Bridge - Reading currently logged-in admin's email address

mattc2
Shopify Partner
1 0 0

I am creating an app which is embedded into Shopify Admin. When the app starts up, I want to read the user's email address, and check whether that email address exists already in my own database. The documentation on the App Bridge makes it seem as though this is possible, but:

- I am using the package @Shopify/app-bridge-react, which seems inconsistent with this documentation. Perhaps this is not fully-featured?

- Even when using App Bridge as a CDN resource, the console logged user object in the snippet below, always has undefined for user.email (in fact all properties are undefined or empty apart from accountAccess), despite the fact I am logged into admin.shopify.com.

 

 
shopify.user().then((user) => console.log(user));


The second part of this problem is that I would like to store some metafield about the relationship between the Shopify user and my own database on Shopify's backend. I can't see that it is possible to store a metafield on the user in this way, however. Is there a different approach I can take, or am I missing something here?

Reply 1 (1)

brdata
Shopify Partner
50 2 12

Hi @mattc2,

 

The app-bridge API returns the admin user email when running within the Shopify POS app.

User (shopify.dev)

 

If your app is running in a browser or in the Shopify Mobile app the user object only contains accountAccess (which is set to "Account owner", "Full access", or "Limited access").

 

You can get the numeric Shopify user id (not email) on your server via the session token (JWT).

Getting started with session token authentication (shopify.dev)

Extract the sub value from the payload. This is the ID of the user that made the request.