mirror of
https://github.com/go-shiori/shiori.git
synced 2024-09-20 23:16:12 +08:00
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:
parent
7e1824a8b5
commit
cba5046231
|
@ -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));
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue