grafana / quickpizza

Pizza, pizza, pizza!
https://quickpizza.grafana.com/
Apache License 2.0
63 stars 15 forks source link

Store and retrieve admin token from browser cookies #50

Closed roobre closed 11 months ago

roobre commented 11 months ago

Prior to this PR, the token returned by /api/login was persisted only in the component state, which caused it to be lost when navigating away from the /admin page.

This PR makes the following changes to persist the admin token:

  1. The /api/login endpoint now returns the token as a cookie in addition to as a json object in the response payload.
  2. The /admin page now processes the cookies sent back by the server. The payload is now ignored.
  3. The /admin page will attempt to load the token from cookie storage if it is present, and allow deleting the cookie with the logout button.
  4. The /api/internal/recommendations allows reading the token from a cookie. This is currently not used by the frontend, which still sends the admin token using the Authorization header.

There is probably an argument to be made that we could get rid of cookies entirely and persist things in localStorage, but I thought using cookies might allow for http-only (i.e. no javascript) tests, if that makes sense.