Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech : Correction d'un comportement étrange sur la connexion par email / mot de passe #11156

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ def expert_signed_in?
current_expert.present?
end

# calling current_user in a before_action will trigger the warden authentication (devise behavior)
# which is not what we want in a before_action of a sign_in action (current_user should be nil before explicit sign_in)
# so we need to override current_user to avoid this
# https://github.com/heartcombo/devise/issues/5602#issuecomment-1876164084
def current_user
super if warden.authenticated?(scope: :user)
end

def current_account
{
gestionnaire: current_gestionnaire,
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/users/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@

context 'when email domain is in mandatory list' do
let(:email) { '[email protected]' }
it 'redirects to agent connect with force parameter' do
it 'redirects to agent connect with force parameter and is not logged in' do
expect(AgentConnectService).to receive(:enabled?).and_return(true)
subject
expect(response).to redirect_to(agent_connect_path(force_agent_connect: true))
expect(flash[:alert]).to eq("La connexion des agents passe à présent systématiquement par AgentConnect")
expect(controller.current_user).to be_nil
end
end
end
Expand Down
Loading