-
-
Notifications
You must be signed in to change notification settings - Fork 374
Verify shopify with SPA #1173
Verify shopify with SPA #1173
Conversation
Hi @enmaboya The one issue potentially I see is you are not loading AppBridge completely is "SPA mode" is enabled because of your conditional added in This would theoretically, not load the app inside the iframe - so can you provide how this works in a real example? |
@Kyon147 the SPA (React in my case) does not need a native AppBridge. Instead, use the npm package "@shopify/app-bridge-react", as in the example I gave, it does the same thing - toast, modal and so on. shopify_spa_app_record.mp4 |
Apologies, totally missed the import for app bridge! |
Hi @enmaboya |
This PR also makes it very React centric, when Laravel bundles with VueJS out the box. As Shopify does not have a "Vue-App-Bridge" package, is this PR maybe constricting users on what languages and frameworks they should be using? I say this as someone who uses React and Vue but uses Vue more exclusively with Laravel. If we merged this in, I think we would be one-sided if we did not offer wikis on both Vue and React implementations. Only because the React/App-Bridge handles the token out the box, with the |
@Kyon147 True... maybe This way, react support initially, and when Vue is figured out, we can check |
@osiset that makes sense - I think the solution would need to be a package like Shopify's react/appbridge package, not sure if one exists so someone would have to make it ha - I do a lot of vue/shopify work so might add it to the list... |
…ture/verify_shopify_with_spa
@osiset @Kyon147 now called "frontend_engine", available values:
Checking via a simple switch, if react is selected, the native app bridge won't load. When using blade or vue, everything works as before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor comment, see if it makes sense.
src/Util.php
Outdated
{ | ||
$currentFrontendEngine = self::getShopifyConfig('frontend_engine') ?? FrontendEngine::BLADE; | ||
|
||
switch ($currentFrontendEngine) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@enmaboya Switch is probably not needed since its only React we need to look for.
return !$currentFrontendEngine->isSame(FrontendEngine::REACT);
So "if current engine is not React, return true and use app bridge"... React will return false and not use app bridge.
I see the error, my bad, I forgot it was Enum. Let me just pull this in locally and adjust something quick and issue a patch to this PR. |
Adjustments made. Moved it to be string based for the config, as scalars are more user friendly for someone doing config (where possible anyways), it also allows for using environment vars to pass in the frontend engine requirement via Enum value for the config would've been fine, but as PHPStan complained, because the Enum methods are magic ( I am good with this, @Kyon147 what do you think? |
@osiset looks good to me and I agree, I think the strings are more readable tbf and just and overall simpler implementation for the same end result. |
@enmaboya how are you getting the token and identifying the currently logged in shop on home route when its clicked the very first time, after installation? I am trying to make it work with Inertia.js, I can get and set the token for all Inertia ( Axios ) requests but the very first request is not Inertia (Axios). Therefore no token and hence |
Just an update on this, billing currently does not work if you want to use the SPA only setting. There's the
So the @osiset @enmaboya |
For everyone who wants to implement SPA, you can use something like this for proper handling requests |
Also, this patch looks like a working solution (at least it works in my case):
|
This looks like a good middle ground solution if people want to continue to use the built-in billing route. Can you create a PR for this @kurakin-oleksandr? |
If you have a SPA frontend (React, Vue, or something else), there is no point in redirecting to the "authenticate.token" route.
Redirecting and then getting the token has the following disadvantages:
This PR adds validation:
if you specified in the settings that you are using SPA, a record is created in the table "users" and this user is not deleted, then the request is skipped.
Then you just need to describe the logic in your frontend.
Example for React: