Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Global redirect
def ensure_clinician_is_logged_in
respond_to do |format|
format.html { redirect_to "/clinicians/sign_in#{build_url_query}" unless current_clinician }
format.json do
response.headers['REQUIRES_AUTH'] = '1'
render js: "/clinicians/sign_in#{build_json_query}" unless current_clinician
end
end
end
export const handleLoginRedirect = (response) => {
if (typeof response.getResponseHeader === 'function' &&
response.getResponseHeader('REQUIRES_AUTH') === '1') {
window.location = response.responseText;
}
};
import { handleLoginRedirect } from 'util/filters';
export function postMessageAttachment(data, doneCb, errCb) {
return function(dispatch) {
return $(data.form).ajaxSubmit({
dataType: 'json',
url: Routes.clinician_app_messages_path({
...dataWithoutForm
}),
type: 'POST',
success(response) {
...
},
error(response) {
handleLoginRedirect(response);
if (errCb) errCb(response);
}
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment