I have two router scopes as follows
scope "/api", Api.Customer do
pipe_through [:api, :customer_auth] # customer has 'key' and 'authorization' header
resources "/help", HelpController, only: [:create]
resources "/profile", ProfileController, only: [:create]
end
scope "/api", Api.Partner do
pipe_through [:api, :partner_auth] # partner has 'key' header
resources "/help", HelpController, only: [:create]
resources "/profile", ProfileController, only: [:create]
end
i want to check if request does not have ‘authorization’ header then request should go to partner scope but i dont have any idea how should i do it. any help is much appreciated.
i can create a plug as follows.
defmodule Api.Auth.AuthHeaderExists do
import Plug.Conn
def init(opts), do: _opts
def call(conn, _opts) do
if header_exists?(conn) do
conn
else
# here i want to redirect the request to partner scope
# or
# how can i skip current scope (customer scope)
# what should i do?
end
end
end