diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bc45b8ebaf..ddc07cdf02 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -200,7 +200,23 @@ def handle_bigbluebutton_error # Manually deal with 401 errors rescue_from CanCan::AccessDenied do |_exception| - render "errors/greenlight_error" + if current_user + render "errors/greenlight_error" + else + # Store the current url as a cookie to redirect to after sigining in + cookies[:return_to] = request.url + + # Get the correct signin path + path = if allow_greenlight_accounts? + signin_path + elsif Rails.configuration.loadbalanced_configuration + omniauth_login_url(:bn_launcher) + else + signin_path + end + + redirect_to path + end end private