gnikyt / laravel-shopify

A full-featured Laravel package for aiding in Shopify App development
MIT License
1.24k stars 374 forks source link

Can't use original Laravel authentication flow. #542

Closed onurdogan1012 closed 3 years ago

onurdogan1012 commented 4 years ago

For bug reporting only! If you're posting a feature request or discussion, please ignore. Hello. First of all, thanks for your job on this package :)

Expected Behavior

Laravel authentication flow works properly.

Current Behavior

When using original Laravel authentication and run below code returns error. $shop_find= User::where('id', $shop->id)->first(); $shopData = $shop_find->api()->request( 'GET', '/admin/api/2019-04/shop.json', [] )['body']['shop']; Return value of Osiset\ShopifyApp\Services\ShopSession::getShop() must implement interface Osiset\ShopifyApp\Contracts\ShopModel or be null, instance of App\AdminUser returned

Failure Information

I used old package version 5.4 and used the User model for the admin dashboard. And I upgraded the package to 12.1 and it is using a User model for shops. So I made the AdminUser model for the dashboard and changed the user model on config/auth.php to App\AdminUser. I followed https://github.com/osiset/laravel-shopify/wiki/Upgrading guide and all other functions work well now.

Steps to Reproduce

  1. Install Laravel and include Shopify-Laravel package
  2. Make AdminUser model that extends Authenticatable.
  3. Change 'users' provider model on config/auth.php.
  4. After login with adminuser data and run Shop->api().

Context

Failure Logs

local.ERROR: Return value of Osiset\ShopifyApp\Services\ShopSession::getShop() must implement interface Osiset\ShopifyApp\Contracts\ShopModel or be null, instance of App\AdminUser returned {"userId":1,"exception":"[object] (TypeError(code: 0): Return value of Osiset\ShopifyApp\Services\ShopSession::getShop() must implement interface Osiset\ShopifyApp\Contracts\ShopModel or be null, instance of App\AdminUser returned at E:\xampp\htdocs\debutify\vendor\osiset\laravel-shopify\src\ShopifyApp\Services\ShopSession.php:373

Kyon147 commented 4 years ago

As you are changing the way to package works it's not really an "issue" with the package.

From what I can tell the ShopModel contract, it is returning your AdminUser instead which is not what it should be doing and you are getting the error. I'd check your AdminUser to make sure you are not incorrectly implementing it with this package. Without seeing your implementation of User and AdminUser we can't really debug it.

gnikyt commented 4 years ago

As @Kyon147 based on the error your user model is not satisfying the interface.

    /**
     * Wrapper for auth->guard()->user().
     *
     * @return IShopModel|null
     */
    public function getShop(): ?IShopModel
    {
        return $this->auth->guard()->user();
    }

Assuming user() is returning your custom model, ensure you've followed the steps in install of wiki for the user model.

byeyasir commented 3 years ago

@onurdogan1012 I understand what you need. I also need to use the package in the same way and

I did some work around and got it. Package is built the way you are going to use it but I have figured out the solution to the need.

Package is build on top of BasicShopifyAPI and here is what I need

    $shop = User::where('name','some.myshopify.com')->first();
    $options = new Options();
    $options->setVersion('2020-01');        
    $api = new BasicShopifyAPI($options);
    $api->setSession(new Session($shop->name, $shop->password));

And then able to make the api call like the below $result = $api->rest('GET', '/admin/orders.json')['body'];

And to use the

Must include at top of your file/Conroller use Osiset\BasicShopifyAPI\BasicShopifyAPI; use Osiset\BasicShopifyAPI\Options; use Osiset\BasicShopifyAPI\Session;

So now you can access the registered store using the Access Token.

byeyasir commented 3 years ago

@onurdogan1012 Just a suggestion. If you need to perform some background operations and there is no need for Store Admin/User to directly use your app then opt "BasicShopifyAPI" instead this one package but still its depend on you app scope.

gnikyt commented 3 years ago

This seems like a customization issue. Closing. Open if you feel its not.