Skip to content

Instantly share code, notes, and snippets.

@garlou
Created April 18, 2017 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garlou/845047c8b027a659c29811b4fbddcec9 to your computer and use it in GitHub Desktop.
Save garlou/845047c8b027a659c29811b4fbddcec9 to your computer and use it in GitHub Desktop.
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