Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoogleLogin

An Igniter installer that patches an Ash Phoenix project with Google OAuth login, admin user support, and authenticated routing defaults.

Source: https://github.com/nettinho/google_login

Prerequisites

This installer is designed to run on top of a ash generated project such as:

mix igniter.new my_app --with phx.new --install ash,ash_phoenix \
  --install ash_postgres,ash_authentication \
  --install ash_authentication_phoenix --setup --yes

Installation

Add google_login as a dependency in your project's mix.exs:

def deps do
  [
    {:google_login, git: "https://github.com/nettinho/google_login.git"}
  ]
end

Then run:

mix deps.get
mix google_login.install

The installer will show a diff of all proposed changes and ask for confirmation before applying.

What it does

The installer applies the following changes to your project:

Google OAuth

  • Adds a google strategy to the User resource (Accounts.User)
  • Adds a register_with_google action with attribute mapping from Google user info
  • Adds user attributes: email, given_name, family_name, picture, is_admin, confirmed_at
  • Adds a unique_email identity
  • Configures Secrets module with secret_for/4 clauses that read GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and GOOGLE_REDIRECT_URI from environment variables
  • Removes the default add_ons block (e.g. log_out_everywhere) from the User resource

Authenticated routing

  • Replaces the default ash_authentication_live_session :authenticated_routes block with one that mounts HomeLive at /
  • Adds an ash_authentication_live_session :admin_routes block that mounts AdminLive at /admin
  • Removes password-specific routes (reset_route, confirm_route, magic_sign_in_route)
  • Removes the default PageController and its templates (replaced by HomeLive)

Admin support

  • Adds an is_admin boolean attribute (default false) to the User resource
  • Adds a live_admin_required guard to LiveUserAuth that checks is_admin
  • Creates HomeLive (authenticated) and AdminLive (admin-only) LiveView pages

AshAdmin

  • Relocates the AshAdmin dashboard route from /admin to /admin/ash inside the dev_routes block, so it doesn't conflict with the custom AdminLive page

UI & Branding

  • Updates the app layout header with navigation, theme toggle, conditional admin link, user email, and sign-out
  • Adds .env to .gitignore

After installation

  1. Generate and run the database migration:

    mix ash_postgres.generate_migrations --name google_login
    mix ash_postgres.migrate
  2. Set the required environment variables (e.g. in a .env file):

    GOOGLE_CLIENT_ID=your_client_id
    GOOGLE_CLIENT_SECRET=your_client_secret
    GOOGLE_REDIRECT_URI=http://localhost:4000/auth/user/google/callback
  3. To make a user an admin, set is_admin: true on their record.

Idempotency

The installer is safe to run multiple times. It checks for existing strategies, secrets, routes, and modules before making changes, so re-running it will not create duplicates.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages