How about...
 
```
def user_return_path
  if invalid_return_urls.include? session['user_return_to']
    dashboard_path
  else
    session['user_return_to']
  end
end

def after_sign_in_path_for(resource)
  save_detected_locale(resource)
  path = user_return_path
  clear_stored_location
  path
end
  
```