discolabs / django-shopify-auth

A package for adding Shopify authentication to a Django app.
MIT License
144 stars 52 forks source link

Reading shop metafields: Discrepancy between AJAX call and backend view behavior #45

Closed aphelionz closed 4 years ago

aphelionz commented 6 years ago

Getting the list of shop metaifleds works great if running on the server in a simple Django view:

def my_view(request):
    with request.user.session:
        shop = shopify.Shop().current()
        print(shop.metafields())    # returns [(metafield(1232543), metafields(143534534), etc]

However, if I do something like this (don't panic, I'm just experimenting) in an AJAX handler, it returns an empty array.

@csrf_exempt
def proxy_request(request):
    shop_user = AuthAppShopUser.objects.get(myshopify_domain=site)
    user = auth.authenticate(request=request, myshopify_domain=site, token=shop_user.token)
    if user:
        auth.login(request, user)

        with request.user.session:
            shop = shopify.Shop().current()
            print(shop.metafields())   # returns []

Thank you for any insight!