feat: session expire time from backend (#437)

* feat: session expire time from backend

Deduplicated logic from backend and frontend where we needed to take the
login checkbox into account for both back and front codebases. Now the
backend will send the frontend the expire time calculated only in one
place.

This is part of a multi-step process that will store sessions in
database, but this will ease the maintenance of this section for now.

* chore: remove test logger
This commit is contained in:
Felipe Martin Garcia 2022-07-23 11:32:53 +02:00 committed by GitHub
parent 7e1824a8b5
commit cba5046231
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View file

@ -105,9 +105,7 @@
return response.json();
}).then(json => {
// Save session id
var sessionAge = this.remember == 1 ? 60 * 60 * 24 * 30 : 60 * 60
var expTime = new Date(Date.now() + sessionAge * 1000).toUTCString();
document.cookie = `session-id=${json.session}; Path=${new URL(document.baseURI).pathname}; Expires=${expTime}`;
document.cookie = `session-id=${json.session}; Path=${new URL(document.baseURI).pathname}; Expires=${json.expires}`;
// Save account data
localStorage.setItem("shiori-account", JSON.stringify(json.account));

View file

@ -82,7 +82,8 @@ func (h *handler) apiLogin(w http.ResponseWriter, r *http.Request, ps httprouter
loginResult := struct {
Session string `json:"session"`
Account model.Account `json:"account"`
}{strSessionID, account}
Expires string `json:"expires"`
}{strSessionID, account, time.Now().Add(expTime).Format(time.RFC1123)}
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(&loginResult)