Fix Bangumi login regression (#1770)

Caused by #1748.

Two different issues actually.

Firstly, the getUsername API call uses the authClient, which uses the
BangumiInterceptor to get the current OAuth data and attach the
Authorization header. However, on login, #1748 did not try to set the
new auth details until after attempting to call getUsername.
This would cause Mihon to think the user was not authenticated with
Bangumi and cancel the process.

This is fixed by having Mihon store the OAuth credentials in the
interceptor first before attempting to call getUsername.

The second issue is a simple trailing dollar sign in the API URL for
the getUsername method. This was removed.

(cherry picked from commit badc229a2312c0c750c34631f303ac4ca970dc71)
This commit is contained in:
MajorTanya 2025-02-25 06:38:33 +01:00 committed by Jobobby04
parent 66f2877a3f
commit 278224676b
2 changed files with 2 additions and 2 deletions

View File

@ -110,11 +110,11 @@ class Bangumi(id: Long) : BaseTracker(id, "Bangumi") {
suspend fun login(code: String) {
try {
val oauth = api.accessToken(code)
interceptor.newAuth(oauth)
// Users can set a 'username' (not nickname) once which effectively
// replaces the stringified ID in certain queries.
// If no username is set, the API returns the user ID as a strings
var username = api.getUsername()
interceptor.newAuth(oauth)
saveCredentials(username, oauth.accessToken)
} catch (_: Throwable) {
logout()

View File

@ -185,7 +185,7 @@ class BangumiApi(
suspend fun getUsername(): String {
return withIOContext {
with(json) {
authClient.newCall(GET("$API_URL/v0/me$"))
authClient.newCall(GET("$API_URL/v0/me"))
.awaitSuccess()
.parseAs<BGMUser>()
.username