Identity does not persist in mobile/desktop project

Not sure if this is a bug or I haven’t set something up properly. In this video you can see that when I login I’m returned the id of the user in console. Then, when I refresh the page identify is false.

Both the login server action and the server connect on page load reference the same server action/api so why does the identity not persist?

Under Global I have “Security Identify”.

Here’s the currectUser api that users the “security Identify” to query for the user. It’s only working on the initial login.

Do you have the credentials option ticked for the currentUser SC component on the page?

No, is that required? Documentation is so lacking on what options are needed for certain things. Let me try that.

When you process the log in, a cookie is sent to the device and stored. This is used later to validate the login for future api requests. Each time you add a SC to a page (or a SC form) that uses a restrict step or the identity, you will need to tick credentials to allow this cookie to be sent with the request.

I have made a feature request that mobile projects have it ticked by default:

1 Like

Thanks @bpj. Now I’m getting a CORS error on the SCs. I think I have it set correctly on the Server.

The CORS error says “wildcard origin not allowed” when I hover over it.

Try this

1 Like

I got it! Had to set the origin to localhost for now. Also had to ensure the trailing slash was not there.

http://localhost:54331

1 Like

Yeah, CORS on mobile projects is a PITA, particularly when testing from the browser

Each time you restart the project a new port is used it looks like yours is currently http://localhost:54331

On your web project that you are using to serve your APIs you need to manually add CORS entries as an array - there’s no way currently to do this through the UI

open /app/config/config.json
then adjust it to show any hostnames that are required:
image

I have some for a main website, and app endpoints but the final one above is my localhost test - I do sometimes need to update the port and publish (usually when I restart Wappler)

3 Likes

Thank you @bpj & @mebeingken!

1 Like

Do you feel it’s worth the hassle working with localhost in the browser? I don’t ever add the web platform to my mobile projects, so wondering if you feel it speeds up dev or provides some other benefit?

It does for me at the current stage. It’s much easier to refresh a browser than emulating a device.

I use it mainly for developing the general design where changes might be frequent and involve small adjustments. I find it quicker to save and reload in browser in these circumstances. Most of the time though I use Simulator as my main tool

I’d be interested to know what you do…

1 Like

That’s what I figured…but to play devils advocate for a minute, I find that forcing an emulator causes me to code more before testing. Instead up jumping back and forth, I code a bunch of things, then test.

I think the answer here is that both methods are valuable. I think I’ll add a browser platform and test it out next week.

But then I’m going to get angry about having to change CORS for localhost!!!

2 Likes