I have created a script to return a valid jwt token for mapkitjs. I have attempted to use both the fetch and xhr methods to call the script, and both methods receive the token, which I can display using a javascript alert call. I know the token is a good token because I can copy the token from the alert and brute force it into the code and the map is displayed. However, I cannot figure out what is wrong with the token in terms of the "expected pattern." I receive this error in the javascript console: "Unhandled Promise Rejection: SyntaxError: The string did not match the expected pattern." I return a simple string that is only the token itself. I have tried returning a json object like {"jwt":"the token"} or {"JWT":"thetoken"}. I tried changing res.test() to res.json(), although probably not at the some time as when I returned the json object. But then, I don't think that is the real problem, because Apple's description on using the token would not be ... then(res => res.text()). Naturally, I assumed that a text string exactly like is quoted using ... 'const jwt = "thetoken"' was what I was supposed to return to the fetch call. Can someone please tell me what I don't understand about the "expected pattern?"
MapKit JS mapkit.init authorizationCallback
I have noticed another thing, aside from the typo above (same, not some). If I change the token returned by the script, meaning send a bad token, I get the dreaded "Token is invalid" message in the javascript console, as well as the "string did not match..." message. Sending the good, valid token seems to be recognized by Apple. So what is up with the string pattern that setRequestHandler gives an Unhandled Promise Rejection?
Ok, no catch! So I added a catch, and now I do not have an unhandled promise rejection with a string did not match error. I just get an alert, which I put in the catch, saying "Promise Rejected." Baby steps, right? No errors in the console, the token seems to be recognized as valid, because if I send a bad one Apple says it's invalid. So why no map? Why is the promise rejected. I clearly do not know what I am doing.
Apple did not list the code correctly so I deleted it
Answer: A quoted "stringtoken"!