Is there a way (environment variable, localStorage, headers sent to server, etc.) to get the username (or some other user id) of the glitch user who is viewing your app?
For example, would there be a way to remix the ‘dream journal’ app so that each entry corresponded with the name of the glitch user who wrote it (or anonymous if it was used without being logged in?)
Appreciate it rajsite. Seems like this isn’t supported at the moment.
Hey @zhammer ,
As for now there’s no way for a Glitch app to know the user’s details, who is browsing the app. For something like this I’d suggest adding authentication of some kind to your app and relying on that.
One workaround you could use would be to manually set Glitch’s authentication token in your app (perhaps in
localStorage ) and then to call the Glitch API using that token to verify project membership. In the browser console for any project’s Editor window
JSON.parse(localStorage.cachedUser).persistentToken will give you the currently-logged-in user’s identifier for calling the API. If you set that value in your app’s localStorage you could then use it to query the API to glean that user’s permissions to the current project.
The Glitch API is currently undocumented and unofficial, but another community member has documented it from publicly-available calls - you can take a look at that in Glitch API & Documentation . It is subject to change at any time, but please let us know if something you’re relying on breaks.
Hope this helps!