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

Enable custom "select store" view. #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ config :shopifex,
api_key: "shopifyapikey123",
secret: "shopifyapisecret456",
webhook_topics: ["app/uninstalled"], # These are automatically subscribed on a store upon install
allowed_drift: 10_000 # session token exp/nbf tolerance in ms (defaults to 10s)
allowed_drift: 10_000, # session token exp/nbf tolerance in ms (defaults to 10s)
custom_select_store: true # Allows to display a custom view when user enters the application outside Shopify (defaults to false)
```

Update your `endpoint.ex` to include the custom body parser. This is necessary for HMAC validation to work.
Expand Down
12 changes: 10 additions & 2 deletions lib/shopifex/plug/shopify_session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ defmodule Shopifex.Plug.ShopifySession do
end

defp respond_invalid(conn) do
web_module = get_web_module(Application.get_env(:shopifex, :custom_select_store, false))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of introducing this extra flag in the config, I wonder if we can detect the presence of a "select-store.html" template within the web_module, if the web_module is provided? If the web_module is provided in the config and a select-store.html is not present, we should fall back to the Shopifex select-store.html.

Think this is possible?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok ok, sounds like a better approach. I'll work on it!


conn
|> put_view(ShopifexWeb.AuthView)
|> put_layout({ShopifexWeb.LayoutView, "app.html"})
|> put_view(web_module.AuthView)
|> put_layout({web_module.LayoutView, "app.html"})
|> render("select-store.html")
|> halt()
end

defp get_web_module(true),
do: Application.get_env(:shopifex, :web_module)

defp get_web_module(_),
do: ShopifexWeb

defp get_locale(conn, token_claims \\ %{})
defp get_locale(%Plug.Conn{params: %{"locale" => locale}}, _token_claims), do: locale

Expand Down