An atproto PDS written in Go
103
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 11920453a6fb7d1e1fe614ce3331916638c5af96 49 lines 1.5 kB view raw
1package server 2 3import ( 4 "github.com/haileyok/cocoon/internal/helpers" 5 "github.com/haileyok/cocoon/models" 6 "github.com/labstack/echo/v4" 7) 8 9type ComAtprotoServerRefreshSessionResponse struct { 10 AccessJwt string `json:"accessJwt"` 11 RefreshJwt string `json:"refreshJwt"` 12 Handle string `json:"handle"` 13 Did string `json:"did"` 14 Active bool `json:"active"` 15 Status *string `json:"status,omitempty"` 16} 17 18func (s *Server) handleRefreshSession(e echo.Context) error { 19 ctx := e.Request().Context() 20 logger := s.logger.With("name", "handleServerRefreshSession") 21 22 token := e.Get("token").(string) 23 repo := e.Get("repo").(*models.RepoActor) 24 25 if err := s.db.Exec(ctx, "DELETE FROM refresh_tokens WHERE token = ?", nil, token).Error; err != nil { 26 logger.Error("error getting refresh token from db", "error", err) 27 return helpers.ServerError(e, nil) 28 } 29 30 if err := s.db.Exec(ctx, "DELETE FROM tokens WHERE refresh_token = ?", nil, token).Error; err != nil { 31 logger.Error("error deleting access token from db", "error", err) 32 return helpers.ServerError(e, nil) 33 } 34 35 sess, err := s.createSession(ctx, &repo.Repo) 36 if err != nil { 37 logger.Error("error creating new session for refresh", "error", err) 38 return helpers.ServerError(e, nil) 39 } 40 41 return e.JSON(200, ComAtprotoServerRefreshSessionResponse{ 42 AccessJwt: sess.AccessToken, 43 RefreshJwt: sess.RefreshToken, 44 Handle: repo.Handle, 45 Did: repo.Repo.Did, 46 Active: repo.Active(), 47 Status: repo.Status(), 48 }) 49}