Fix overwrite of existing cookiejar.

This commit is contained in:
y a t s
2026-06-18 10:02:16 -04:00
parent 1e9bd059f0
commit 72840af90e
5 changed files with 64 additions and 31 deletions
+18 -5
View File
@@ -122,18 +122,31 @@ func (kf *KF) TwoFactorAuth(ctx context.Context, resp *http.Response, code uint3
return kf.Do(req)
}
func (kf *KF) RefreshSession(ctx context.Context) error {
func (kf *KF) IsLoggedIn() bool {
return getCookie(kf.client.Jar, kf.domain, "xf_user") != nil
}
func (kf *KF) RefreshSession(ctx context.Context) (string, error) {
const COOKIE_NAME = "xf_session"
jar := kf.client.Jar
// Clear any existing session token to request a new one.
setCookie(kf.domain, kf.client.Jar, &http.Cookie{
Name: "xf_session",
setCookie(jar, kf.domain, &http.Cookie{
Name: COOKIE_NAME,
Value: "",
})
resp, err := kf.Get(ctx, kf.domain)
if err != nil {
return err
return "", err
}
resp.Body.Close()
return nil
session := getCookie(jar, kf.domain, COOKIE_NAME)
if session == nil {
return "", errors.New("Failed to get new xf_session cookie.")
}
return session.Value, nil
}