Skip to content

Commit 2076e26

Browse files
authored
refactor: session expiration handler (#135)
* refactor: don't force session expiration * fix: grammar
1 parent 43256e9 commit 2076e26

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lua/leetcode/api/auth.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function Auth.handle(res, err)
3636
err = {}
3737

3838
if (not config.is_cn and auth.id == vim.NIL) or (config.is_cn and auth.slug == vim.NIL) then
39-
err.msg = "Session expired?"
39+
err.msg = "Cookie expired?"
4040
elseif not auth.is_signed_in then
4141
err.msg = "Sign-in failed"
4242
elseif not auth.is_verified then

lua/leetcode/api/statistics.lua

+8-1
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,16 @@ function statistics.streak(cb)
135135
if err then
136136
return cb(nil, err)
137137
end
138+
138139
local data = res.data
139140
local streak = data["streakCounter"]
140-
cb(streak)
141+
142+
if streak == vim.NIL then
143+
err = { msg = "Failed to load streak counter" }
144+
cb(nil, err)
145+
else
146+
cb(streak)
147+
end
141148
end,
142149
})
143150
end

lua/leetcode/api/utils.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ function utils.check_err(err)
151151

152152
if err.status then
153153
if err.status == 401 or err.status == 403 then
154-
require("leetcode.command").expire()
155-
err.msg = "Session expired? Enter a new cookie to keep using `leetcode.nvim`"
154+
-- require("leetcode.command").expire()
155+
err.msg =
156+
"Your cookie may have expired, or LeetCode has temporarily restricted API access"
156157
end
157158
end
158159

0 commit comments

Comments
 (0)