fixed MAL not auto logging in when app starts

This commit is contained in:
2025-12-21 00:24:25 -05:00
parent 5c4caf68e6
commit 063c5016f3
2 changed files with 24 additions and 3 deletions

View File

@@ -308,7 +308,16 @@ func refreshMyAnimeListAuthorizationToken() {
func (a *App) GetMyAnimeListLoggedInUser() MyAnimeListUser { func (a *App) GetMyAnimeListLoggedInUser() MyAnimeListUser {
a.MyAnimeListLogin() a.MyAnimeListLogin()
user := createUser()
if user.Name == "" {
refreshMyAnimeListAuthorizationToken()
user = createUser()
}
return user
}
func createUser() MyAnimeListUser {
client := &http.Client{} client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.myanimelist.net/v2/users/@me?fields=anime_statistics", nil) req, _ := http.NewRequest("GET", "https://api.myanimelist.net/v2/users/@me?fields=anime_statistics", nil)
@@ -335,6 +344,7 @@ func (a *App) GetMyAnimeListLoggedInUser() MyAnimeListUser {
} }
return user return user
} }
func (a *App) LogoutMyAnimeList() string { func (a *App) LogoutMyAnimeList() string {

View File

@@ -1,7 +1,10 @@
<script lang="ts"> <script lang="ts">
import { import {
aniListAnime, aniListAnime,
aniListLoggedIn,
GetAnimeSingleItem, GetAnimeSingleItem,
malLoggedIn,
simklLoggedIn,
} from "./helperModules/GlobalVariablesAndHelperFunctions.svelte"; } from "./helperModules/GlobalVariablesAndHelperFunctions.svelte";
import {onMount} from "svelte"; import {onMount} from "svelte";
import Router from "svelte-spa-router" import Router from "svelte-spa-router"
@@ -16,9 +19,17 @@
import {AniListGetSingleAnimeDefaultData} from "./helperDefaults/AniListGetSingleAnime"; import {AniListGetSingleAnimeDefaultData} from "./helperDefaults/AniListGetSingleAnime";
onMount(async () => { onMount(async () => {
await CheckIfAniListLoggedInAndLoadWatchList() let isAniListLoggedIn: boolean
await CheckIfMALLoggedInAndSetUser() let isMALLoggedIn: boolean
await CheckIfSimklLoggedInAndSetUser() let isSimklLoggedIn: boolean
aniListLoggedIn.subscribe((value) => isAniListLoggedIn = value)
malLoggedIn.subscribe((value) => isMALLoggedIn = value)
simklLoggedIn.subscribe((value) => isSimklLoggedIn = value)
console.log(isAniListLoggedIn)
!isAniListLoggedIn && await CheckIfAniListLoggedInAndLoadWatchList()
!isMALLoggedIn && await CheckIfMALLoggedInAndSetUser()
!isSimklLoggedIn && await CheckIfSimklLoggedInAndSetUser()
}) })
</script> </script>