Session for development store vs live store

Highlighted
Shopify Partner
23 3 0

This is for a standalone app....

 

On a successful app installation, i redirect to the login page, whether or not a user in the standalone app is logged in or not.  I then have them either log in or sign up.  This then attaches the User to the Shop model.

 

I use Devise for authentication

 

Here is my registration controller (the session controller looks almost exactly the same)

class Users::RegistrationsController < Devise::RegistrationsController
  # before_action :configure_sign_up_params, only: [:create]
  # before_action :configure_account_update_params, only: [:update]
  include ShopifyApp::Localization
  include ShopifyApp::LoginProtection

  protect_from_forgery with: :exception
  before_action :login_again_if_different_shop
  around_action :shopify_session, if: :shop_session

  # GET /resource/sign_up
  def new
    super
    if shop_session
      shop_domain = ShopifyAPI::Shop.current.domain
      shop = Shop.find_by(shopify_domain: shop_domain)
    end
  end

  # POST /resource
  def create
    super
    if shop_session
      shop_domain = ShopifyAPI::Shop.current.domain
      shop = Shop.find_by(shopify_domain: shop_domain)
      shop.update_attribute(:company_id, resource.id)
      shop.save!
    end
  end

This all works on installing the app with a development store.

 

When I try to install the app on a live Shopify site, it gives me the error:

 

`undefined method update_attribute for nil class`

 

Is there an extra step needed for live stores I am unaware of?

 

I have tested this many time in development with success on 3 different browsers.  I test it with the same 3 browsers with Live Shopify stores and it doesn't work.

 

Are the sessions with live stores somehow different in any way?

 

Anyone else taking authenticated email accounts and attaching them to the Shop model.  If so, how are you doing this in Production?

 

All in all, this isn't so bad because this standalone app is meant for one company and I can manually add the company account in the User model to the Shop model but this is still frustrating none the less

 

and to clarify, the same issue happens in the Sessions controller as well.  All works fine with development stores, but not the live one

0 Likes
Highlighted
Shopify Partner
23 3 0

This error was due to finding the actual domain attached  to the shopify store instead of the shopify_domain

0 Likes