I have a plug called Subdomain
in charge of setting the subdomain private variable to the conn
object, and also applying a custom secondary router called SubdomainRouter
.
It work fine, however I’m trying to add a validation rule that if someone visits a subdomain for a team that doesn’t exist, I redirect them to the root page.
Does anyone know how to redirect from within a Plug?
def call(conn, router) do
case get_subdomain(conn.host) do
subdomain when byte_size(subdomain) > 0 ->
case MyApp.TeamQueries.get_by_slug(subdomain) do
nil ->
conn
|> Redirect to home somehow? https://localhost:4443
|> halt
team ->
conn
|> put_private(:subdomain, subdomain)
|> router.call(router.init({}))
|> halt
end
_ -> conn
end
end