Y艒ten: A social tracker for your language learning journey built on the atproto.

feat(handlers/login): use slogger #13

merged opened by brookjeynes.dev targeting master from push-trrpxxyxxmot
Labels

None yet.

Participants 1
AT URI
at://did:plc:4mj54vc4ha3lh32ksxwunnbh/sh.tangled.repo.pull/3m3bmdlgblr22
+10 -7
Diff #0
+10 -7
internal/server/handlers/login.go
··· 3 import ( 4 "context" 5 "fmt" 6 - "log" 7 "net/http" 8 "strings" 9 ··· 17 ) 18 19 func (h *Handler) Login(w http.ResponseWriter, r *http.Request) { 20 switch r.Method { 21 case http.MethodGet: 22 var user *types.User ··· 24 if oauth != nil { 25 bskyProfile, err := bsky.GetBskyProfile(oauth.Did) 26 if err != nil { 27 - log.Println("failed to get bsky profile:", err) 28 } 29 user = &types.User{ 30 OauthUser: *oauth, ··· 54 55 // Basic handle validation 56 if !strings.Contains(handle, ".") { 57 - log.Println("invalid handle format:", handle) 58 htmx.HxError(w, http.StatusBadGateway, fmt.Sprintf("'%s' is an invalid handle. Did you mean %s.bsky.social?", handle, handle)) 59 return 60 } ··· 67 Event: ph.UserSignInInitiatedEvent, 68 }) 69 if err != nil { 70 - log.Println("failed to enqueue posthog event:", err) 71 } 72 } 73 } ··· 83 } 84 85 func (h *Handler) Logout(w http.ResponseWriter, r *http.Request) { 86 did := h.Oauth.GetDid(r) 87 88 err := h.Oauth.DeleteSession(w, r) 89 if err != nil { 90 - log.Println("failed to logout", "err", err) 91 } else { 92 - log.Println("logged out successfully") 93 } 94 95 if !h.Config.Core.Dev && did != "" { ··· 98 Event: ph.UserLoggedOutEvent, 99 }) 100 if err != nil { 101 - log.Println("failed to enqueue posthog event:", err) 102 } 103 } 104
··· 3 import ( 4 "context" 5 "fmt" 6 "net/http" 7 "strings" 8 ··· 16 ) 17 18 func (h *Handler) Login(w http.ResponseWriter, r *http.Request) { 19 + l := h.Logger.With("handler", "Login") 20 + 21 switch r.Method { 22 case http.MethodGet: 23 var user *types.User ··· 25 if oauth != nil { 26 bskyProfile, err := bsky.GetBskyProfile(oauth.Did) 27 if err != nil { 28 + l.Error("failed to get bsky profile", "err", err) 29 } 30 user = &types.User{ 31 OauthUser: *oauth, ··· 55 56 // Basic handle validation 57 if !strings.Contains(handle, ".") { 58 + l.Error("invalid handle format", "err", handle) 59 htmx.HxError(w, http.StatusBadGateway, fmt.Sprintf("'%s' is an invalid handle. Did you mean %s.bsky.social?", handle, handle)) 60 return 61 } ··· 68 Event: ph.UserSignInInitiatedEvent, 69 }) 70 if err != nil { 71 + l.Error("failed to enqueue posthog event", "err", err) 72 } 73 } 74 } ··· 84 } 85 86 func (h *Handler) Logout(w http.ResponseWriter, r *http.Request) { 87 + l := h.Logger.With("handler", "Logout") 88 + 89 did := h.Oauth.GetDid(r) 90 91 err := h.Oauth.DeleteSession(w, r) 92 if err != nil { 93 + l.Error("failed to logout", "err", err) 94 } else { 95 + l.Error("logged out successfully") 96 } 97 98 if !h.Config.Core.Dev && did != "" { ··· 101 Event: ph.UserLoggedOutEvent, 102 }) 103 if err != nil { 104 + l.Error("failed to enqueue posthog event", "err", err) 105 } 106 } 107

History

1 round 0 comments
sign up or login to add to the discussion
brookjeynes.dev submitted #0
1 commit
expand
feat(handlers/login): use slogger
expand 0 comments
pull request successfully merged