mirror of
https://github.com/mihonapp/mihon.git
synced 2025-03-01 18:34:13 +01:00
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.
This commit is contained in:
parent
277d8bad8e
commit
badc229a23
@ -105,11 +105,11 @@ class Bangumi(id: Long) : BaseTracker(id, "Bangumi") {
|
|||||||
suspend fun login(code: String) {
|
suspend fun login(code: String) {
|
||||||
try {
|
try {
|
||||||
val oauth = api.accessToken(code)
|
val oauth = api.accessToken(code)
|
||||||
|
interceptor.newAuth(oauth)
|
||||||
// Users can set a 'username' (not nickname) once which effectively
|
// Users can set a 'username' (not nickname) once which effectively
|
||||||
// replaces the stringified ID in certain queries.
|
// replaces the stringified ID in certain queries.
|
||||||
// If no username is set, the API returns the user ID as a strings
|
// If no username is set, the API returns the user ID as a strings
|
||||||
var username = api.getUsername()
|
var username = api.getUsername()
|
||||||
interceptor.newAuth(oauth)
|
|
||||||
saveCredentials(username, oauth.accessToken)
|
saveCredentials(username, oauth.accessToken)
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
logout()
|
logout()
|
||||||
|
@ -153,7 +153,7 @@ class BangumiApi(
|
|||||||
suspend fun getUsername(): String {
|
suspend fun getUsername(): String {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
with(json) {
|
with(json) {
|
||||||
authClient.newCall(GET("$API_URL/v0/me$"))
|
authClient.newCall(GET("$API_URL/v0/me"))
|
||||||
.awaitSuccess()
|
.awaitSuccess()
|
||||||
.parseAs<BGMUser>()
|
.parseAs<BGMUser>()
|
||||||
.username
|
.username
|
||||||
|
Loading…
x
Reference in New Issue
Block a user