datasette
datasette copied to clipboard
Idea: `datasette.set_actor_cookie(response, actor)`
I just wrote this code in a plugin and it felt like it could benefit from an abstraction: https://github.com/simonw/datasette-auth0/blob/152e6eb21e96e9b73bd9c205f9749a1297d0ef0b/datasette_auth0/init.py#L79-L92
redirect_response = Response.redirect("/")
expires_at = int(time.time()) + (24 * 60 * 60)
redirect_response.set_cookie(
"ds_actor",
datasette.sign(
{
"a": profile_response.json(),
"e": baseconv.base62.encode(expires_at),
},
"actor",
),
)
return redirect_response
I don't want to do a response.set_actor_cookie() method because I like Response not to carry too many Datasette-specific features.
So datasette.set_actor_cookie(response, actor, expire_after=None) would be a better place for this I think.
Then I can update this section of the documentation which currently recommends the above pattern: https://docs.datasette.io/en/stable/authentication.html#the-ds-actor-cookie