mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-28 17:49:38 +02:00
Another attempt at fixing MFA issues
This commit is contained in:
parent
071ad52c7f
commit
e49bda4a2e
2 changed files with 21 additions and 2 deletions
|
@ -28,12 +28,22 @@ module Authentication
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_session_by_cookie
|
def find_session_by_cookie
|
||||||
Session.find_by(id: cookies.signed[:session_token])
|
cookie_value = cookies.signed[:session_token]
|
||||||
|
Rails.logger.info "Looking for session with cookie value: #{cookie_value.present? ? 'present' : 'missing'}"
|
||||||
|
session = Session.find_by(id: cookie_value)
|
||||||
|
Rails.logger.info "Session found: #{session.present? ? 'yes' : 'no'}"
|
||||||
|
session
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_session_for(user)
|
def create_session_for(user)
|
||||||
session = user.sessions.create!
|
session = user.sessions.create!
|
||||||
cookies.signed.permanent[:session_token] = { value: session.id, httponly: true }
|
Rails.logger.info "Setting session cookie with value: #{session.id}"
|
||||||
|
# Explicitly set SameSite attribute and ensure cookie is set properly
|
||||||
|
cookies.signed.permanent[:session_token] = {
|
||||||
|
value: session.id,
|
||||||
|
httponly: true,
|
||||||
|
same_site: :lax
|
||||||
|
}
|
||||||
session
|
session
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,15 @@ class MfaController < ApplicationController
|
||||||
session.delete(:mfa_user_id)
|
session.delete(:mfa_user_id)
|
||||||
@session = create_session_for(@user)
|
@session = create_session_for(@user)
|
||||||
Rails.logger.info "MFA verification successful for user #{@user.id}. Session created: #{@session.id}"
|
Rails.logger.info "MFA verification successful for user #{@user.id}. Session created: #{@session.id}"
|
||||||
|
|
||||||
|
# Explicitly set the cookie again to ensure it's properly set
|
||||||
|
cookies.signed.permanent[:session_token] = {
|
||||||
|
value: @session.id,
|
||||||
|
httponly: true,
|
||||||
|
same_site: :lax
|
||||||
|
}
|
||||||
|
|
||||||
|
# Use turbo: false to ensure a full page reload
|
||||||
redirect_to root_path, turbo: false
|
redirect_to root_path, turbo: false
|
||||||
else
|
else
|
||||||
flash.now[:alert] = t(".invalid_code")
|
flash.now[:alert] = t(".invalid_code")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue