Shopifex v0.6.1 ShopifexWeb.AuthController behaviour View Source

You can use this module inside of another controller to handle initial iFrame load and shop installation

Example:

defmodule MyAppWeb.AuthController do
  use MyAppWeb, :controller
  use ShopifexWeb.AuthController

  # Thats it! Validation, installation are now handled for you :)
end

Link to this section Summary

Callbacks

An optional callback called after the installation is completed, the shop is persisted in the database and webhooks are registered. By default, this function redirects the user to the app within their Shopify admin panel.

An optional callback which you can use to override how your app is rendered on initial load. If you are building a server-rendered app, you might just want to redirect to your index page. If you are building an externally hosted SPA, you probably want to redirect to the Shopify admin link for your app.

An optional callback which is called after the shop data has been retrieved from Shopify API. This function should persist the shop data and return a shop record.

Link to this section Types

Specs

shop() :: %{access_token: String.t(), scope: String.t(), url: String.t()}

Link to this section Callbacks

Link to this callback

after_install(arg1, shop)

View Source (optional)

Specs

after_install(Plug.Conn.t(), shop()) :: Plug.Conn.t()

An optional callback called after the installation is completed, the shop is persisted in the database and webhooks are registered. By default, this function redirects the user to the app within their Shopify admin panel.

Example

@impl true
def after_install(conn, shop) do
  # send yourself an e-mail about shop installation

  # follow default behaviour.
  super(conn, shop)
end
Link to this callback

auth(conn, params)

View Source (optional)

Specs

auth(conn :: Plug.Conn.t(), params :: Plug.Conn.params()) :: Plug.Conn.t()

An optional callback which you can use to override how your app is rendered on initial load. If you are building a server-rendered app, you might just want to redirect to your index page. If you are building an externally hosted SPA, you probably want to redirect to the Shopify admin link for your app.

Externally hosted SPA's will likely only hit this route on install.

Link to this callback

insert_shop(shop)

View Source (optional)

Specs

insert_shop(shop()) :: shop()

An optional callback which is called after the shop data has been retrieved from Shopify API. This function should persist the shop data and return a shop record.

Example

@impl true
def insert_shop(shop) do
  # make sure there is only one store in the database because we don't have
  # a unique index on the url column for some reason.

  case Shopifex.Shops.get_shop_by_url(shop.url) do
    nil -> super(shop)
    shop -> shop
  end
end