From 74b923f06f0adf4265f36fc02c8c178cc17c549d Mon Sep 17 00:00:00 2001 From: y a t s <65122-yats@users.noreply.gitgud.io> Date: Fri, 19 Jun 2026 10:21:21 -0400 Subject: [PATCH] Fix IsLoggedIn() and some other error checking --- auth.go | 7 ++++--- auth_test.go | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/auth.go b/auth.go index 9a20a80..de4ac36 100644 --- a/auth.go +++ b/auth.go @@ -123,7 +123,8 @@ func (kf *KF) TwoFactorAuth(ctx context.Context, resp *http.Response, code uint3 } func (kf *KF) IsLoggedIn() bool { - return kf.Cookies.GetCookie(kf.domain, "xf_user") != nil + cookie := kf.Cookies.GetCookie(kf.domain, "xf_user") + return !(cookie == nil || cookie.Value == "") } func (kf *KF) RefreshSession(ctx context.Context) (string, error) { @@ -142,8 +143,8 @@ func (kf *KF) RefreshSession(ctx context.Context) (string, error) { resp.Body.Close() session := kf.Cookies.GetCookie(kf.domain, COOKIE_NAME) - if session == nil { - return "", errors.New("Failed to get new xf_session cookie.") + if session == nil || session.Value == "" { + return "", fmt.Errorf("Failed to get new %s cookie", COOKIE_NAME) } return session.Value, nil diff --git a/auth_test.go b/auth_test.go index dd70e41..6d26832 100644 --- a/auth_test.go +++ b/auth_test.go @@ -64,12 +64,19 @@ func TestLogin(t *testing.T) { t.Logf("2FA response: %+v\n", lr) } + t.Logf("Checking RefreshSession()") session, err := kf.RefreshSession(ctx) if err != nil { t.Error(err) return } t.Logf("xf_session: %s\n", session) + + t.Logf("Checking IsLoggedIn()\n") + if !kf.IsLoggedIn() { + t.Error("IsLoggedIn() test returned false.") + return + } } func genTest2FACode() (uint32, error) {