Created
April 18, 2017 13:39
-
-
Save garlou/845047c8b027a659c29811b4fbddcec9 to your computer and use it in GitHub Desktop.
Global redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const handleLoginRedirect = (response) => { | |
if (typeof response.getResponseHeader === 'function' && | |
response.getResponseHeader('REQUIRES_AUTH') === '1') { | |
window.location = response.responseText; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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