I am implementing a custom error reporting form for an application to allow users to report errors into the issue tracker (YouTrack) directly from the application.
function createIssue() {
$.ajax({
url: "http://example.myjetbrains.com/youtrack/rest/user/login",
dataType: "json",
type: "POST",
data: {
login: $("#username").val(),
password: $("#password").val()
}
});
$.ajax({
url: "http://example.myjetbrains.com/youtrack/rest/issue",
dataType: "json",
type: "POST",
data: {
project: 'PROJECT_NAME',
summary: $("#summary").val(),
description: $("#description").val()
},
xhrFields: {
withCredentials: true
}
}).done(function(data) {
$("#result").show();
$("#summary").val('');
$("#description").val('');
});
}
The first ajax request which is to log the user into the external system is something I only want to happen if the user is not already logged in. Since the cookie is set for the remote domain when a login session exists how I can first check whether I need to try and log the user in first?
If I attempt the first request when the user already has a session I get an error from the service which is why I want to perform this check first.