ShopifexWeb.AuthController behaviour (Shopifex v2.2.1) 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 called after the oauth update is completed. 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
Link to this section Callbacks
Specs
after_install(Plug.Conn.t(), shop(), oauth_state :: String.t()) :: 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, oauth_state) do
# send yourself an e-mail about shop installation
# follow default behaviour.
super(conn, shop, oauth_state)
end
Specs
after_update(Plug.Conn.t(), shop(), oauth_state :: String.t()) :: Plug.Conn.t()
An optional callback called after the oauth update is completed. By default, this function redirects the user to the app within their Shopify admin panel.
Example
@impl true
def after_update(conn, shop, oauth_state) do
# do some work related to oauth_state
# follow default behaviour.
super(conn, shop, oauth_state)
end
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.
Specs
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