mirror of
https://github.com/usememos/memos.git
synced 2024-12-19 09:02:49 +03:00
fix: persist jwt expires by cookie (#2509)
fix pesist jwt expires by cookie
This commit is contained in:
parent
f67757f606
commit
52fdf8bccd
@ -106,8 +106,11 @@ func (s *APIV1Service) SignIn(c echo.Context) error {
|
||||
}
|
||||
|
||||
var expireAt time.Time
|
||||
// Set cookie expiration to 100 years to make it persistent.
|
||||
cookieExp := time.Now().AddDate(100, 0, 0)
|
||||
if !signin.Remember {
|
||||
expireAt = time.Now().Add(auth.AccessTokenDuration)
|
||||
cookieExp = time.Now().Add(auth.CookieExpDuration)
|
||||
}
|
||||
|
||||
accessToken, err := auth.GenerateAccessToken(user.Username, user.ID, expireAt, []byte(s.Secret))
|
||||
@ -117,7 +120,6 @@ func (s *APIV1Service) SignIn(c echo.Context) error {
|
||||
if err := s.UpsertAccessTokenToStore(ctx, user, accessToken); err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("failed to upsert access token, err: %s", err)).SetInternal(err)
|
||||
}
|
||||
cookieExp := time.Now().Add(auth.CookieExpDuration)
|
||||
setTokenCookie(c, auth.AccessTokenCookieName, accessToken, cookieExp)
|
||||
userMessage := convertUserFromStore(user)
|
||||
return c.JSON(http.StatusOK, userMessage)
|
||||
|
Loading…
Reference in New Issue
Block a user