defmodule PhoenixKitWeb.Components.OAuthButtons do @moduledoc """ OAuth authentication buttons component for Google and Apple Sign-In. This component automatically checks if OAuth is available and configured. If OAuth is not available (dependencies not installed or not enabled in settings), the buttons will not be rendered. """ use Phoenix.Component alias PhoenixKit.Users.OAuthAvailability alias PhoenixKit.Utils.Routes alias PhoenixKitWeb.Components.Core.Icons @doc """ Renders OAuth provider buttons for authentication. This component only renders buttons if: - OAuth is enabled in settings (oauth_enabled = true) - Ueberauth library is loaded - At least one provider is configured ## Examples <.oauth_buttons /> <.oauth_buttons show_divider={false} /> <.oauth_buttons class="mt-6" /> """ attr :class, :string, default: "" attr :show_divider, :boolean, default: true def oauth_buttons(assigns) do # Check each provider individually assigns = assigns |> assign(:google_enabled, OAuthAvailability.provider_enabled?(:google)) |> assign(:apple_enabled, OAuthAvailability.provider_enabled?(:apple)) |> assign(:github_enabled, OAuthAvailability.provider_enabled?(:github)) |> assign(:facebook_enabled, OAuthAvailability.provider_enabled?(:facebook)) # Check if at least one provider is enabled any_provider_enabled = assigns.google_enabled or assigns.apple_enabled or assigns.github_enabled or assigns.facebook_enabled assigns = assign(assigns, :any_provider_enabled, any_provider_enabled) ~H""" <%= if @any_provider_enabled do %>
<%= if @show_divider do %>
Or continue with
<% end %>
<%!-- Google Sign-In Button --%> <%!-- OAuth routes are non-localized, so we use locale: :none --%> <%= if @google_enabled do %> <.link href={Routes.path("/users/auth/google", locale: :none)} class="btn btn-outline w-full flex items-center justify-center gap-2 hover:bg-base-200 transition-all hover:scale-[1.02] active:scale-[0.98]" > Continue with Google <% end %> <%!-- Apple Sign-In Button --%> <%= if @apple_enabled do %> <.link href={Routes.path("/users/auth/apple", locale: :none)} class="btn btn-outline w-full flex items-center justify-center gap-2 hover:bg-base-200 transition-all hover:scale-[1.02] active:scale-[0.98]" > Continue with Apple <% end %> <%!-- GitHub Sign-In Button --%> <%= if @github_enabled do %> <.link href={Routes.path("/users/auth/github", locale: :none)} class="btn btn-outline w-full flex items-center justify-center gap-2 hover:bg-base-200 transition-all hover:scale-[1.02] active:scale-[0.98]" > Continue with GitHub <% end %> <%!-- Facebook Sign-In Button --%> <%= if @facebook_enabled do %> <.link href={Routes.path("/users/auth/facebook", locale: :none)} class="btn btn-outline w-full flex items-center justify-center gap-2 hover:bg-base-200 transition-all hover:scale-[1.02] active:scale-[0.98]" > Continue with Facebook <% end %>
<% end %> """ end end