torikushiii / hoyolab-auto

Auto check-in and others for any Hoyoverse games
https://ko-fi.com/torikushiii
GNU Affero General Public License v3.0
78 stars 18 forks source link

Failed to redeem code: Please login to your account first #36

Closed djdoolky76 closed 1 month ago

djdoolky76 commented 2 months ago

Seems auto redeem is not working. Same on other Hoyoverse games, but auto check-in works fine

image

torikushiii commented 2 months ago

that's cookie related issue, try refreshing your cookies first

Capoouo commented 2 months ago

that's cookie related issue, try refreshing your cookies first

It's been five days since the last time I got the cookie, and issues related to this have also arisen. Is there a better way to handle this situation now?

torikushiii commented 2 months ago

It's been five days since the last time I got the cookie, and issues related to this have also arisen. Is there a better way to handle this situation now?

I'll try looking into it, but so far non of my accounts is needed refreshing since weeks

abigailwillow commented 2 months ago

I refreshed my cookie just yesterday, and this happened for me as well.

torikushiii commented 2 months ago

@djdoolky76 @Capoouo @abigailwillow as of this commit, i've added a method that should refresh your cookie every 2 hour, if some of you still using config.js file, please migrate to config.jsonc using this guide for easier migration

Capoouo commented 2 months ago

@djdoolky76 @Capoouo @abigailwillow as of this commit, i've added a method that should refresh your cookie every 2 hour, if some of you still using config.js file, please migrate to config.jsonc using this guide for easier migration

Thank you for the quick update <3 BTW, I encountered this message. Will it cause any other issues?

2024-07-17 21:12:58 hoyolab-auto | 2024-07-17 21:12:58 { message: 'Failed to fetch data from Game8.', statusCode: 502 }

Or can I just ignore it?

torikushiii commented 2 months ago

You can safely ignore it. It's just the website is not reachable at the moment.

Capoouo commented 1 month ago

You can safely ignore it. It's just the website is not reachable at the moment.

I noticed that it has been changed to JSON5, but currently, mine is JSONC. So, I need to run convert.js to JSON5, right? In that case, do I need to modify the code in convert.js to convert JSONC to JSON5?

edit : I used an online formatter to convert JSONC to JSON5 and changed the format to JSON5. Currently, there are no issues

abigailwillow commented 1 month ago

I noticed that it has been changed to JSON5, but currently, mine is JSONC. So, I need to run convert.js to JSON5, right? In that case, do I need to modify the code in convert.js to convert JSONC to JSON5?

edit : I used an online formatter to convert JSONC to JSON5 and changed the format to JSON5. Currently, there are no issues

Sorry for this, there was a small transition period between the two. For anyone else still running into this issue, the following code can be used to convert JSONC to JSON5.

const file = require("node:fs");
const JSON5 = require("json5");
const { jsonc } = require('jsonc');

const config = jsonc.readSync("./config.jsonc");

function kebabToCamelCase (object) {
    for (const key of Object.keys(object)) {
        if (object[key] && typeof object[key] === "object" && !Array.isArray(object[key])) {
            kebabToCamelCase(object[key]);
        }

        const convertedKey = key.replace(/-./g, match => match[1].toUpperCase());

        if (key !== convertedKey) {
            object[convertedKey] = object[key];
            delete object[key];
        }
    }
}

kebabToCamelCase(config);

file.writeFileSync("./config.json5", JSON5.stringify(config, null, 4));
console.log("config.jsonc converted to config.json5");

[!NOTE] This requires the JSONC package to be installed, which can be installed by running the npm i jsonc command in your terminal.

djdoolky76 commented 1 month ago

I'm going to close this issue. Three days have passed since the testing, and the cookie issue seems fixed. Thanks for the hard work @torikushiii

JustArion commented 1 month ago

I'm still experiencing the issue. Could multiple accounts from various locations cause cookie invalidation? The code redemption fails on all accounts except for the first.

95922e92-62db-465f-9590-290b19726185_01-08-2024

torikushiii commented 1 month ago

@JustArion multiple accounts should not be causing this, I have 3 accounts currently running with redemption code enabled and never had any issue with this, try refreshing your cookie first and see how it goes, if the problem still persist I'll try investigate it further.

djdoolky76 commented 1 month ago

mine is still fine, I'm using multiple accounts and all codes redeemed successfully

JustArion commented 1 month ago

@JustArion multiple accounts should not be causing this, I have 3 accounts currently running with redemption code enabled and never had any issue with this, try refreshing your cookie first and see how it goes, if the problem still persist I'll try investigate it further.

The issue still persists. I refreshed the cookie. It works when testing redeem code. I wait a few days. It prompts to log in again.

Screenshot_20240810_102431_Discord.jpg

The project is running on a VPS in a docker container running 24/7

torikushiii commented 1 month ago

@JustArion alright, thank you for letting me know, I'll try to replicate this issue if possible and figure it out how to deal with this.

JustArion commented 2 weeks ago

@torikushiii Here's some additional info I hope might be useful. I've noticed my ./data/ folder is empty (apart from the README.md)

I've also taken the liberty to attach the logs from make logs for you under the debug log level (accounts redacted for anonymity, hope you can understand) logs.log

I've also attached my current config file (File extension renamed to be able to upload to GitHub .json5 -> .json). config.json

The above was done after doing a git pull and a make update then waiting for a code check. and then doing a manual redeem via Discord for a fake key.

My assumption would be that the tokens aren't refreshed or they're not stored on my end. Is there a way I can confirm / remedy this?

torikushiii commented 2 weeks ago

@JustArion is this still regarding the same issue with this topic?

token should be refreshed every 2 hour as you can see here

https://github.com/torikushiii/hoyolab-auto/blob/main/crons/update-cookie/index.js

and here

https://github.com/torikushiii/hoyolab-auto/blob/1a8a85515b84e0889e58d763fb59de4fe1e07ed0/hoyolab-modules/template.js#L532-L581

you should see a log if any of the cookie update is failed.

As far as I know, Hoyo can invalidate your cookie for various reasons, and I'm not sure which ones yet. One of the reasons could be logging out from Hoyolab, changing the password, or they could just invalidate it because they detect that the device fingerprint does not match. I'm still exploring options, but so far, no luck.

JustArion commented 2 weeks ago

@JustArion is this still regarding the same issue with this topic?

Yea

As far as I know, Hoyo can invalidate your cookie for various reasons, and I'm not sure which ones yet. One of the reasons could be logging out from Hoyolab, changing the password, or they could just invalidate it because they detect that the device fingerprint does not match. I'm still exploring options, but so far, no luck.

Alrighty, good luck!

JustArion commented 2 weeks ago

For note regarding my current VPS, the associated IP has the following info from ipapi that may be of interest.

is_bogon      : False
is_mobile     : False
is_crawler    : False
is_datacenter : True
is_tor        : False
is_proxy      : False
is_vpn        : False
is_abuser     : False

With an abuser score of 0.0024 (Low)