feat(api): persist and expose garmin_connected on successful auth
This commit is contained in:
@@ -32,10 +32,11 @@ type SessionConfig struct {
|
||||
}
|
||||
|
||||
type sessionMeResponse struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
HasProfile bool `json:"has_profile"`
|
||||
DisplayName string `json:"display_name,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
HasProfile bool `json:"has_profile"`
|
||||
DisplayName string `json:"display_name,omitempty"`
|
||||
GarminConnected bool `json:"garmin_connected"`
|
||||
}
|
||||
|
||||
func (s *Server) handleSessionLogin(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -113,6 +114,12 @@ func (s *Server) handleSessionMe(w http.ResponseWriter, r *http.Request) {
|
||||
if u, found := userFromContext(r.Context()); found {
|
||||
resp.HasProfile = true
|
||||
resp.DisplayName = u.DisplayName
|
||||
profile, err := s.DB.GetProfile(r.Context(), u.ID)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
resp.GarminConnected = profile.GarminConnectedAt != nil
|
||||
}
|
||||
writeJSON(w, http.StatusOK, resp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user