Closed Kungpowpow closed 1 year ago
@Kungpowpow
I can't be 100% sure without trying it replicate it but what does your test
method look like? I can also see that host
is not being pass through either which will also cause issues.
@Kungpowpow are you still finding this issue?
Closing issue as it looks stale, re-open if issue persists.
Hi @Kungpowpow did you ever find a resolution for submitting non-SPA forms?
Normal links work perfectly fine multiple times over (even if I add GET parameters to them e.g. <a href="{{ URL::tokenRoute('home', ['test' => 1]) }}">
) but I tried 4 different ways of submitting a form and even when I got it to submit successfully I always lose the session token on the resulting pageload.
{{ URL::tokenRoute('myroute') }}
I get the error The POST method is not supported for route authenticate/token
{{ URL::tokenRoute('myroute') }}
, I immediately get the Attempt to read property "name" on null
error*{{ route('myroute') }}
, it works but after submitting it the sessionToken is blank, so any further links I click on result in the Attempt to read property "name" on null
error*, or if I submit the form again I get No authenticated user or shop domain
{{ route('myroute') }}
, it works but after submitting it the sessionToken is blank, so any further links I click on result in the Attempt to read property "name" on null
error*, or if I submit the form again I get No authenticated user or shop domain
Is there something else I'm missing in the form other than including @sessionToken?
* error comes from default.blade.php where Auth::user() is null:
apiKey: "{{ \Osiset\ShopifyApp\Util::getShopifyConfig('api_key', $shopDomain ?? Auth::user()->name ) }}",
Unfortunately I couldn't get it working. I switched to react for making my app and couldn't continue testing this.
@Kungpowpow Ah ok, thanks for letting me know. I seem to have almost been able to work around this now by explicitly passing $request->input('host')
to my view and then passing it on with <input type="hidden" name="host" value="{{ $host }}">
Then I can use either GET or POST with action={{ route('myroute') }}
(not tokenRoute) and do so over and over long as I'm passing along the 'host' value each time it will still have the session token on the next page etc.
EDIT: However, after the first form submit, any regular links are still broken, so although I can use the link multiple times and then submit the form multiple times, as soon as I've submitted the form the link stops working. e.g. After I submit form and then click <a href="{{ URL::tokenRoute('home', ['host'=>$host]) }}">Link</a>
(with or without including host) I get Attempt to read property "name" on null
. Very strange... putting this down for today, I'll post back if I find a way to make form submits AND links work!
Using this fix instead of passing the $host value myself also leaves me in the same predicament: https://github.com/Kyon147/laravel-shopify/pull/194
Perhaps this is related to issue #200 @Kyon147 ? Although I tried applying this change and it didn't make any difference for me for this.
@tom-rice it sounds like you are not getting the host
param consistently. This is a known thing for blade templates and you have to pass the host
param on every request or page change for blade.
I'd use xDebug or similar to step through your code and see where the issue stems from and why by looking at the data available at that point in the app. There's too many variables from each app, to know from such a generic error of the user not being defined.
Thank you @Kyon147 I have now fixed the last issue I was having by changing same_site
from lax
to none
in config/session.php - thanks to this comment you posted in issue #82
So the whole solution was 2 things: 1) Used the change in this pull request to always include the host parameter in @sessionToken output rather than passing it through the form myself: https://github.com/Kyon147/laravel-shopify/pull/194 Could that pull request be included in a future release?
2) Set "same_site": "none" in config/session.php Perhaps this could be explicitly noted in the installation or routing wiki, unless it's mentioned somewhere already and I missed it?
Now I can POST to {{ route('myroute') }} multiple times and continue to click on tokenRoute URLs without issue 😃
@tom-rice glad you got it working. The PR i've just merged into main, now that the pipeline has passed - so I'll get an official patch out this week for it.
Glad that my cookie investigation has come in use. I don't think i've added it to the wiki yet which is a good suggestion as it will affect mainly Blade template uses, because they rely on the session state whereas SPA uses, typically use a JS based state like VueX etc.
I've added some blade specific support notes to the installation section, this should reduce issues popping up for set up too hopefully.
https://github.com/Kyon147/laravel-shopify/wiki/Installation#blade-specific-support
Expected Behavior
Load the route & view from a submitted form.
Current Behavior
I'm trying to submit a form via GET, and the page errors out after reload. The Auth::user() is null when the page is loaded after form submit, however the Auth::user() works completely fine on first page load. The @sessionToken works fine on first load, and is empty after submission.
Ideally my goal is to submit to a controller via POST so I can validate the form. "return Redirect::tokenRedirect('apply');" was giving me similar errors with that method. My code shared below is an attempt to reduce this to a simpler recreateable format.
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
Context
Failure Logs
https://flareapp.io/share/4m4xOwBm#F66