mirror of
https://gitgud.io/yats/libkiwi.git
synced 2026-06-20 18:15:29 -04:00
Fix overwrite of existing cookiejar.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user