<commit_before>class AuthController < ApplicationController
  before_action :set_oauth_user, only: [:facebook, :google] 

  def signup
    @user = User.create auth_params
    render json: auth_success
  end

  def login
    @user = User.find_by email: params[:email] if params[:email].present?

    if @user && @user.authenticate(params[:password])
      render json: auth_success
    else
      render json: { message: 'Invalid credentials' }, status: :unauthorized
    end
  end

  def facebook
    render json: auth_success
  end

  def google
    render json: auth_success
  end

  private

  def set_oauth_user
    @oauth = OAuth.const_get(action_name.capitalize).new params
    
    @user = User.for_oauth @oauth
  end

  def auth_params
    params.require(:auth).permit(:email, :password, :displayName)
  end

  def auth_success
    { token: Token.encode(@user.id) }
  end
end<commit_msg>Make oauth endpoints more explicit<commit_after>class AuthController < ApplicationController

  def signup
    @user = User.create auth_params
    render json: auth_success
  end

  def login
    @user = User.find_by email: params[:email] if params[:email].present?

    if @user && @user.authenticate(params[:password])
      render json: auth_success
    else
      render json: { message: 'Invalid credentials' }, status: :unauthorized
    end
  end

  def facebook
    @oauth = OAuth.const_get(action_name.capitalize).new params
    
    @user = User.for_oauth @oauth

    render json: { token: Token.encode(@user.id) }
  end

  def google
    @oauth = OAuth.const_get(action_name.capitalize).new params
    
    @user = User.for_oauth @oauth

    render json: { token: Token.encode(@user.id) }
  end

  private

  def auth_params
    params.require(:auth).permit(:email, :password, :displayName)
  end
end
{'fraction_non_alphanumeric': 0.09584487534626039, 'fraction_numerical': 0.0, 'mean_word_length': 3.36231884057971, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '677880', 'n_tokens_mistral': 588, 'n_tokens_neox': 560, 'n_words': 148}