Skip to content

Commit 1c45e40

Browse files
authored
fix: leetcode-cn can not use GitHub log in bug (#46)
1 parent 404420e commit 1c45e40

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/plugins/leetcode.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,16 @@ plugin.login = function(user, cb) {
540540
};
541541

542542
function parseCookie(cookie, body, cb) {
543+
const isCN = config.app === 'leetcode.cn';
543544
const SessionPattern = /LEETCODE_SESSION=(.+?)(;|$)/;
544-
const csrfPattern = /csrftoken=(.+?)(;|$)/;
545+
let csrfPattern;
546+
if (isCN) {
547+
csrfPattern = /name="csrfmiddlewaretoken" value="(.*?)"/;
548+
} else {
549+
csrfPattern = /csrftoken=(.+?)(;|$)/;
550+
}
551+
const reCsrfResult = csrfPattern.exec(isCN? body: cookie);
545552
const reSessionResult = SessionPattern.exec(cookie);
546-
const reCsrfResult = csrfPattern.exec(cookie);
547553
if (reSessionResult === null || reCsrfResult === null) {
548554
return cb('invalid cookie?');
549555
}

0 commit comments

Comments
 (0)