diff --git a/.sample.env b/.sample.env index 07107de..493455f 100644 --- a/.sample.env +++ b/.sample.env @@ -8,3 +8,5 @@ EXECJS_RUNTIME=Node GITHUB_CLIENT_ID=consumer_public_key GITHUB_CLIENT_SECRET=consumer_secret_key GITHUB_TEAM_ID=yourteamid +SKIP_TEAM_CHECK=false +DEVELOPER_EMAIL=developer@foo.com diff --git a/app/controllers/auth_controller.rb b/app/controllers/auth_controller.rb index 3574f8e..bd0c777 100644 --- a/app/controllers/auth_controller.rb +++ b/app/controllers/auth_controller.rb @@ -2,16 +2,36 @@ class AuthController < ApplicationController skip_before_action :authenticate_user!, only: [:oauth_callback] def oauth_callback - if team_member? - user = User.find_or_create_by(email: auth_email) - sign_in(user) - flash[:success] = "You successfully signed in" - redirect_to root_path + if ok_to_bypass_authentication? + create_user(developer_email) + else + if team_member? + create_user(auth_email) + end end end private + def create_user(email) + user = User.find_or_create_by(email: email) + sign_in(user) + flash[:success] = "You successfully signed in" + redirect_to root_path + end + + def ok_to_bypass_authentication? + Rails.env == "development" && skip_team_check? + end + + def skip_team_check? + ENV["SKIP_TEAM_CHECK"].downcase == "true" + end + + def developer_email + ENV["DEVELOPER_EMAIL"] + end + def team_member? auth_hash.credentials.team_member? end