achievements-app/psn-api

Report CORS errors when attempting to exchange the NPSSO token

Closed this issue · 2 comments

Users trying to make psn-api's auth calls in a SPA will always hit a CORS error. We should make it loud and clear when this happens via throwing a different kind of error. Right now, users see an inaccurate message saying that something is wrong with their NPSSO.

From what I've looked up, there is no way to know a CORS happened using Javascript. The browser will inform the user visually through the console GUI, but such error won't be returned to the javascript file/request/function itself. (Reference: here, but scroll up a little and check the blue box)

We can, however, detect if the user is running the files on the browser or on the server.

// When ran will return true on the browser and false on the server.
const isBrowser = () => {try {return this===window;}catch(e){ return false;};}

// When ran will return false on the browser and true on the server.
const isNode =() => {try {return this===global;}catch(e){return false;}}

// Will return "true false" on the browser and "false true" on the server.
console.log(isBrowser(), isNode())

I guess we gonna implement this using isBrowser()? Unless there is a better way to do it which I'm missing?

I've decided to close this as I'm not sure we should even be recommending to use this library in client-side settings anymore.