Two IDX Projects Talking to Each Other (401 error)

Good day! Before I start I have searched the forum and I did read This article able how to get two apps to talk. That is how I got as far as I have! This may end up being just someone looking at my code and telling me what I’m doing wrong because I’m not seeing it.

I have two projects:

So far, pretty simple. The Express App when pinged will call the Flask app and return what the Flask app gets from Gemini.

In the Flask app I added CORS and as you can see I added the full URL for the Express app for the “origins” attribute. I have also tried this with setting CORS authorization for any origin. In the nix file I also added the PORT and API_SERVICE urls. When starting the app I do:

export PORT=5000
export API_SERVICE="https://$PORT-$WEB_HOST"

and echo it out, boot the app, click the link and it opens in a new tab. This base URL is the swagger ui page and I can “Try it out!” and it all works. CURL-ing my endpoint also works. Good great!

So then when I start up the Express app I immediately get a 401 error - Not Authorized. This is not a CORS error mind you - the Flask app never actually gets pinged. Whatever built in mechanism there is for security rejects the call before it actually makes it to the route.

Inspecting the Network tab when I hit my actual endpoint I can see there is a WorkstationJwt included but that appears missing when the Express app sends its request. I thought including withCredentials: true in my request would be enough to take care of that.

Anyway - I’m at a loss now. I feel like I am really close (or at least close to replacing my 401 with a CORS error lol). Not sure what to do from here, any assistance would be appreciated.

R/
Philip

I wanted to add this, seeing weird behavior thats probably irrelevant. One of the forums or posts mentioned to manually start the app after setting up my ENVs however when I manually stop the app when IDX boots up, then open a new terminal and do my commands, then start the app - I can’t open ANOTHER terminal.

This happens in both apps. Anyone else seeing this? Pretty weird. It opens the terminal then immediately closes it.

I’ve recently seen that, terminal opens then immediately closes…
I got it back by doing, command pallet, idx environment rebuild.

1 Like

Probably no harm in posting the whole error:

Error: Not authorized

401: The Workstation does not exist or your currently signed in account does not have access to it. <eye3 title='/Workstations.GetWorkstation, PERMISSION_DENIED'/> APPLICATION_ERROR;google.cloud.workstations.v1beta/Workstations.GetWorkstation;Permission 'workstations.workstations.get' denied on 'projects/monospace-1/locations/us-east4/workstationClusters/workstation-cluster-10/workstationConfigs/monospace-config-web/workstations/idx-stinky-pinky-brain-1722037466462';AppErrorCode=7;StartTimeMs=1723577331303;unknown;Deadline(sec)=10.0;ResFormat=uncompressed;ServerTimeSec=0.143198083;LogBytes=256;Non-FailFast;EffSecLevel=privacy_and_integrity;ReqFormat=uncompressed;ReqID=f827cc9bf4e315c5;GlobalID=0;Server=[2002:a72:8086:0:b0:121:c326:16a4]:4002

Hey actually you know what worked was just copying and pasting the JWT token from my devtools into Thunderclient and running it. So no CORS problem at all!

But thats not a solution, I can’t manually copy the JWT token into my app every time it expires. So why isn’t the Express app creating this JWT for me?

I have 3rd party cookies enabled and I have both the / main route and /api routes open in my browser - with my request set up like so:

    const response = await axios.get(apiUrl + 'api/generate', {
      baseURL: apiUrl,
      headers: {
        'Content-Type': 'application/json',
        'Cookie': req.header.cookies
      },
      withCredentials: true,
    });

but that doesn’t do the trick. I’l just be putting the JWT into my .env for now until I get this figured out/a better local setup.

Just bumping/updating. I haven’t really found a solution for this. I’ve simply been keeping the copied JWT in my .env.

My next big step is dev deployment and this issue won’t matter there but I’d still like to get a good local setup going.

Hi @Philip_Godfrey - we are very close to exposing public ports to allow you to make this all work without any of the JWT workarounds.

Some other workarounds beyond what you’ve discovered may be covered here: Full-stack development in Project IDX

Cheers,
Kirupa :slight_smile:

1 Like