-
Notifications
You must be signed in to change notification settings - Fork 94
Description
A JWT contains a payload of some kind, with the most basic info being the user.id
. It's also very helpful to have information about a current user in the frontend as storable json
, such as claims (eg: a name), preferences (e.g: light/dark theme), scopes, or in my case, using the shortUUID
of a user rather than it's incremental Int
id (for security and preventing data scraping).
These would get stored in localStorage
or a cookie, depending on the authentication method. Having user data readily available saves having to ping the database whenever we need info, and currently I don't think I'd be able to use the default auth methods (from what I understand they only return basic data about the user?).
Auth0's JWT looks something like this:
{
"endpoint": "https://endpoint.auth0.com/",
"userid": "authmethod|1234",
"iat": 1759761022,
"exp": 1759768222,
"scope": "openid email update:current_user _metadata",
"clientid": "yzMIDmaXAW"
}
You then have to ping a getProfile
url to grab user data.
{ app_metadata = Nothing, email = "[email protected]", email_verified = False, name = Nothing, nickname = Nothing, picture = Nothing, user_id = "1234", updated_at = Nothing, user_metadata = Just { json = "light theme", prefs = ["one","two","three"] } }
I'm not sure what's the best practice for JWTs and Session cookies, but ideally a feature that combines these two things into one API call, that we can extend with user details we'd need. I'm not a fan of Auth0's API or their docs, which seem overly complicated for authentication.
If other Piccolo users are anything like me they're not confident with security (or prefer to outsource the task), and "subclassing the class and implementing it yourself" isn't really an option.
Seems like a handy addition for frontend apps to me?