X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=kraftakt.go;h=f6b3d9ca085adaef6e8fe54a0acc0a43d6b1b45d;hb=51c94afc942687a447069f43de406e31c319a64e;hp=4768da8a0f05877dd268885e4fb69d8681edc9c2;hpb=6edb36816137a6ae2246eb8858fa3453dce8ab79;p=kraftakt.git diff --git a/kraftakt.go b/kraftakt.go index 4768da8..f6b3d9c 100644 --- a/kraftakt.go +++ b/kraftakt.go @@ -136,8 +136,13 @@ func loginHandler(_ context.Context, w http.ResponseWriter, r *http.Request, _ * return nil } -func fitbitConnectHandler(_ context.Context, w http.ResponseWriter, r *http.Request, _ *app.User) error { - http.Redirect(w, r, fitbit.AuthURL(), http.StatusTemporaryRedirect) +func fitbitConnectHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, u *app.User) error { + c, err := fitbit.NewClient(ctx, "", u) + if err != nil { + return err + } + + http.Redirect(w, r, c.AuthURL(ctx), http.StatusTemporaryRedirect) return nil } @@ -196,8 +201,13 @@ func fitbitDisconnectHandler(ctx context.Context, w http.ResponseWriter, r *http return nil } -func googleConnectHandler(_ context.Context, w http.ResponseWriter, r *http.Request, _ *app.User) error { - http.Redirect(w, r, gfit.AuthURL(), http.StatusTemporaryRedirect) +func googleConnectHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, u *app.User) error { + c, err := gfit.NewClient(ctx, u) + if err != nil { + return err + } + + http.Redirect(w, r, c.AuthURL(ctx), http.StatusTemporaryRedirect) return nil } @@ -277,6 +287,8 @@ func fitbitNotifyHandler(ctx context.Context, w http.ResponseWriter, r *http.Req // handleNotifications parses fitbit notifications and requests the individual // activities from Fitbit. It is executed asynchronously via the delay package. func handleNotifications(ctx context.Context, payload []byte) error { + log.Debugf(ctx, "NOTIFY -> %s", payload) + if err := app.LoadConfig(ctx); err != nil { return err }