You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
defaultAuthenticationHandler should use a JWT #1720
Is your feature request related to a problem? Please describe.
On await session.auth.authenticatedUserId, defaultAuthenticationHandler calls
var authKey =await tempSession.dbNext.findById<AuthKey>(keyId);
That means that every HTTPS request hits the database once before the request can even be handled. This database roundtrip could dramatically decrease server performance (e.g. if all endpoints require the user to be logged in, and all HTTPS requests run one additional lightweight query, then verifying the user for every session would decrease the server performance and therefore the scalability by 50%).
Describe the solution you'd like
There needs to be a better AuthenticationHandler that does not hit the database.
The userId and the UserInfo object should be serialized and then encrypted with salt, along with a time to live, then base64-encoded to create a cookie that is shipped to the user. The user can send that cookie back to the server anytime, and the server can trust that cookie as long as the time to live has not been exceeded (because only the server is able to decrypt it).
This will prevent the need to hit the database at all, unless the client doesn't yet have this cookie (on first connect), or the time to live has been exceeded -- in which case, the database is queried, and a new cookie is generated.
changed the title [-]Need cryptographic replacement for `defaultAuthenticationHandler` that does not hit the database[/-][+]`defaultAuthenticationHandler` should use a JWT so that it does not hit the database[/+]on Jan 17, 2024
changed the title [-]`defaultAuthenticationHandler` should use a JWT so that it does not hit the database[/-][+]`defaultAuthenticationHandler` should use a JWT[/+]on Jan 17, 2024
Activity
Isakdl commentedon Jan 8, 2024
I think a simple JWT implementation would be sufficient for this (and a common web standard).
lukehutch commentedon Jan 8, 2024
You're right, I forgot that there is a standard for this these days!
Here's a library that implements this for Dart:
https://pub.dev/packages/dart_jsonwebtoken
I don't think it would be much work to utilize this in Serverpod.
[-]Need cryptographic replacement for `defaultAuthenticationHandler` that does not hit the database[/-][+]`defaultAuthenticationHandler` should use a JWT so that it does not hit the database[/+][-]`defaultAuthenticationHandler` should use a JWT so that it does not hit the database[/-][+]`defaultAuthenticationHandler` should use a JWT[/+]marcelomendoncasoares commentedon Mar 26, 2026
Closing since JWT is now the default on the templates since Serverpod 3.0 with the new auth.