Files
openfoodnetwork/app/controllers/omniauth_callbacks_controller.rb
David Cook f6f1a005cb Add spec
Oh, and a transaction block. Because the controller after hooks tried to update the DB which resulted in
  PG::InFailedSqlTransaction: ERROR:  current transaction is aborted, commands ignored until end of transaction block

Even for a small rescue statement, it's worth adding a spec. You never know what might not be working!
2025-02-12 16:10:36 +11:00

22 lines
623 B
Ruby

# frozen_string_literal: true
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def openid_connect
ActiveRecord::Base.transaction do
OidcAccount.link(spree_current_user, request.env["omniauth.auth"])
end
redirect_to admin_oidc_settings_path
rescue ActiveRecord::RecordNotUnique
flash[:error] = t("devise.oidc.record_not_unique", uid: request.env["omniauth.auth"].uid)
redirect_to admin_oidc_settings_path
end
def failure
error_message = request.env["omniauth.error"].to_s
flash[:error] = t("devise.oidc.failure", error: error_message)
super
end
end