Open app after HTTP request

I have an app that generates a temporary user to enter the app and have a personalized experience.

I, as an admin, create this user and upload information about him. I want to create an url like:

exampleapp.anvil.app/UserCode

So that when the user opens it, he enters the anvil app, and the app already knows which user is in it.

I tried using HTTP requests, but those are taken in the server and return a json response, but does not open the app afterwards.

Does anyone has any idea how can I accomplish this? Or maybe a starting point?

I would look into using routing.

https://anvil-extras.readthedocs.io/en/latest/guides/modules/routing.html

1 Like

Another way to go about this is using a the normal users service and only enabling login via magic links, and only allowing Admin to enable users via the users table.
This would allow them to use a special link sent to their email which would automatically log them in.

It would not however look like exampleapp.anvil.app/SpecialNonChangingUserCode in the browser, it would just be a new link every time they logged in that went to their email. The first link could be generated to their email by you after you created the user an enabled it.

Kind of like how 2FA via email works, but at every login.

1 Like

You can’t do: exampleapp.anvil.app/UserCode
But you can: exampleapp.anvil.app/#?usercode=abc&reason=def
Then you can get the query string (the part after the #) as a dictionary. See the docs here: Anvil Docs | Navigation

The routing module of Anvil Extras mentioned by @anthonys builds on that to create a nice navigation system.

5 Likes

See the last section of Anvil Docs | Creating HTTP APIs

It shows you how you can redirect users to a URL.

This is exactly what I needed.

Thank you