Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to undefined method App\Models\User::getSessionContext() in Shopify mobile app #175

Open
adamndev opened this issue Jun 4, 2023 · 6 comments
Labels
bug Something isn't working unconfirmed Bug has not been reproduced yet

Comments

@adamndev
Copy link

adamndev commented Jun 4, 2023

For bug reporting only! If you're posting a feature request or discussion, please ignore.

Expected Behavior

Be able to load the app inside of the Shopify mobile app.

Current Behavior

App throws a 500:

Call to undefined method App\Models\User::getSessionContext()

Failure Information

App loads without issue in a browser, but something is going sideways when loading it in an iframe or whatever context is used within Shopify's mobile app.

Initially thought this might be related to IframeProtection in some way, but tried the trick from this issue but the error stays the same.

I have Octane running, but I also tried disabling it and there was no change there.

Side question, is Octane likely to function ok considering all of the session/token related bits happening behind the scenes?

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Load the app inside the mobile app.

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Package Version: ^18.1
  • Laravel Version: ^9.40
  • PHP Version: 8.1
  • Template Engine: Blade
  • Using a toolset (Docker, Laradock, Vagrant, etc.): Vapor

Failure Logs

Please include any relevant log snippets or files here.

@adamndev adamndev added bug Something isn't working unconfirmed Bug has not been reproduced yet labels Jun 4, 2023
@Kyon147
Copy link
Owner

Kyon147 commented Jun 5, 2023

@adamndev I'm just getting a project set up so I can test this, will come back to you as quick as I can.

Octane I could not say, as I've not used it or tested it with the package.

@adamndev
Copy link
Author

adamndev commented Jun 5, 2023

Thanks @Kyon147, no rush!

Also, probably important context I forgot to mention - I have a Shop model that I'm using over the default users table, but not sure I've seen anywhere to specify this, only the table name for the migrations. I would guess that the error above is because it defaults to the user model. Strange how it's only this scenario though. Thanks for the help!

@Kyon147
Copy link
Owner

Kyon147 commented Jun 5, 2023

It could be because you are using a Shop model actually, i'd need to take a look and see if we have hardcoded something that could be throwing the error.

My apps open fine inside the Shopify app but they are also not on blade, so the process is a bit different for SPAs

@xiangsgao
Copy link

xiangsgao commented Jul 7, 2023

Hi,
I am facing the same issue
I am also using a different model for shopify user authentication.
this what i changed from the default configuration

in auth.php

'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],

        'shopify' => [
            'driver' => 'eloquent',
            'model' => App\Models\ShopifyShop::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'shopify' => [
            'driver' => 'session',
            'provider' => 'shopify',
        ],
    ],

'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_reset_tokens',
            'expire' => 60,
            'throttle' => 60,
        ],
        'shopify' =>[
            'provider' => 'shopify',
            'table' => 'password_reset_tokens',
            'expire' => 60,
            'throttle' => 60,
        ]
    ],

and my current shopify-app.php

 'shop_auth_guard' => env('SHOPIFY_SHOP_AUTH_GUARD', "shopify")
 'shop_auth_provider' => env('SHOPIFY_SHOP_AUTH_PROVIDER', 'shopify')

i can see my app install successfully and the shopify user gets populated in the database but it always end up in a Call to undefined method App\Models\User::getSessionContext() error afterward.

If there something I am missing? such as middleware or such?

@Kyon147
Copy link
Owner

Kyon147 commented Jul 12, 2023

@adamndev @xiangsgao - can you guys swap back to the default for testing and see if the app loads?

@xiangsgao
Copy link

xiangsgao commented Jul 12, 2023

I have resolved my issue.
Main problem is line 253 from the VerifyShop.php

$previousContext = $this->previousShop ? $this->previousShop->getSessionContext() : null;

The issue is the middleware is still using the original and default laravel auth guard which uses the user model. rather than my own custom model as you can see in line 133

    // Set the previous shop (if available)
    if ($request->user()) {
        $this->previousShop = $request->user();
    }

To fix this, I created my own middleware that runs before this

public function handle(Request $request, Closure $next): Response
{
    if (($guard = Util::getShopifyConfig('shop_auth_guard'))) {
        $this->auth->setDefaultDriver($guard);
    }
    return $next($request);
}

I hope this helps anyone who is facing similar issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed Bug has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

3 participants