To my understanding, you’re dealing with 2 very different things that don’t hold hands per se.
StorefrontAccessToken -This is set to give api access to your store. Checking orders, plugins, paid themes, that sort of thing.
For you to have “back stage access” to a store (or more appropriately for your plugin to have access to someone’s store data) you have to give them access.
This access token is a part of that security handshake.
Customer -This object gets created once the customer has been logged in. -Yes, the customer must exist in the store to log in, but for this object to exist in liquid, you have to have the actual customer logged in.
Short answer: If you view the site without being logged in, the customer object won’t be created. Calling it will not return a customer object. Hence nil.
I’m having the same problem. I’m creating a custom storefront using the shopify graphql. So on my login page when I log in the user using the customerAccessTokenCreate everything works fine:
In the result I don’t get errors and I receive an access token. But when I try to use that access token for other queries, like getting the customer info:
query getCustomer($customerAccessToken: String!) {
customer(customerAccessToken: $customerAccessToken) {
acceptsMarketing
addresses(last: 5) {
edges {
node {
address1
address2
city
company
country
countryCodeV2
firstName
formatted
formattedArea
id
lastName
latitude
longitude
name
phone
province
provinceCode
zip
}
}
}
createdAt
displayName
email
firstName
id
lastName
numberOfOrders
phone
updatedAt
}
}
There’s a lot to unpack here as far as how all this should work.
My suggestion which should cover all bases is:
1: find working example code and modify it.
2: That access token belongs to an account. Check which permissions it has on your store.
2.1: whatever the administrator of a store cannot see, the highest permission settings cannot see either.
2.2: a lot of your store data is more open than you think, such as variants and prices. Google “shopify store json”
3: shopify houses the userdata. Other than basic stuff, access is/should be out of the store owner’s hands unless it is tied to an order.
4: look up the api you are using weather you’re using php or something else to ping for the data. If the data is protected (used in system but not accessible outward) you cannot query it. You can try, but null data is what you will be given as a graceful crash.
This would be something I do for a fee, but I’m tied atm and can’t give this the priority it deserves. However, if you get further and would like assistance, just reply to this thread.