From 90b68b717a0df4bbfba72df1a61ff5f657df26a6 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Thu, 15 Aug 2024 16:16:40 -0400 Subject: [PATCH] added logout functions --- AniListUserFunctions.go | 15 +++++++++ MALUserFunctions.go | 15 +++++++++ SimklUserFunctions.go | 14 ++++++++ frontend/src/AvatarMenu.svelte | 8 ++--- .../GlobalVariablesAndHelperFunctions.svelte | 32 ++++++++++++++++++- 5 files changed, 79 insertions(+), 5 deletions(-) diff --git a/AniListUserFunctions.go b/AniListUserFunctions.go index 1dbe2ee..71c4129 100644 --- a/AniListUserFunctions.go +++ b/AniListUserFunctions.go @@ -200,3 +200,18 @@ func (a *App) GetAniListLoggedInUser() AniListUser { return post } + +func (a *App) LogoutAniList() string { + if (AniListJWT{} != aniListJwt) { + err := aniRing.Remove("anilistTokenType") + err = aniRing.Remove("anilistTokenExpiresIn") + err = aniRing.Remove("anilistAccessToken") + err = aniRing.Remove("anilistRefreshToken") + + if err != nil { + fmt.Println("AniList Logout Failed", err) + } + } + + return "AniList Logged Out Successfully" +} diff --git a/MALUserFunctions.go b/MALUserFunctions.go index 63e133d..062598a 100644 --- a/MALUserFunctions.go +++ b/MALUserFunctions.go @@ -256,3 +256,18 @@ func (a *App) GetMyAnimeListLoggedInUser() MyAnimeListUser { return user } + +func (a *App) LogoutMyAnimeList() string { + if (MyAnimeListJWT{} != myAnimeListJwt) { + err := myAnimeListRing.Remove("MyAnimeListTokenType") + err = myAnimeListRing.Remove("MyAnimeListExpiresIn") + err = myAnimeListRing.Remove("MyAnimeListAccessToken") + err = myAnimeListRing.Remove("MyAnimeListRefreshToken") + + if err != nil { + fmt.Println("MAL Logout Failed", err) + } + } + + return "MAL Logged Out Successfully" +} diff --git a/SimklUserFunctions.go b/SimklUserFunctions.go index 9265c4e..7f89143 100644 --- a/SimklUserFunctions.go +++ b/SimklUserFunctions.go @@ -193,3 +193,17 @@ func (a *App) GetSimklLoggedInUser() SimklUser { return user } + +func (a *App) LogoutSimkl() string { + if (SimklJWT{} != simklJwt) { + err := simklRing.Remove("SimklTokenType") + err = simklRing.Remove("SimklAccessToken") + err = simklRing.Remove("SimklScope") + + if err != nil { + fmt.Println("Simkl Logout Failed", err) + } + } + + return "Simkl Logged Out Successfully" +} diff --git a/frontend/src/AvatarMenu.svelte b/frontend/src/AvatarMenu.svelte index 1d61755..e1880bc 100644 --- a/frontend/src/AvatarMenu.svelte +++ b/frontend/src/AvatarMenu.svelte @@ -2,7 +2,7 @@ import {Avatar} from "flowbite-svelte"; import type {AniListUser} from "./anilist/types/AniListTypes"; - import {aniListLoggedIn, aniListUser, malLoggedIn, simklLoggedIn,} from "./GlobalVariablesAndHelperFunctions.svelte" + import {aniListLoggedIn, aniListUser, malLoggedIn, simklLoggedIn, logoutOfAniList, logoutOfMAL, logoutOfSimkl} from "./GlobalVariablesAndHelperFunctions.svelte" import * as runtime from "../wailsjs/runtime"; let currentAniListUser: AniListUser @@ -43,7 +43,7 @@ aria-labelledby="dropdownUserAvatarButton"> {#if isAniListLoggedIn}
  • - @@ -51,7 +51,7 @@ {/if} {#if isMALLoggedIn}
  • - @@ -59,7 +59,7 @@ {/if} {#if isSimklLoggedIn}
  • - diff --git a/frontend/src/GlobalVariablesAndHelperFunctions.svelte b/frontend/src/GlobalVariablesAndHelperFunctions.svelte index 741977b..76b1e34 100644 --- a/frontend/src/GlobalVariablesAndHelperFunctions.svelte +++ b/frontend/src/GlobalVariablesAndHelperFunctions.svelte @@ -2,7 +2,7 @@ import { GetAniListItem, GetAniListLoggedInUser, GetAniListUserWatchingList, GetMyAnimeListLoggedInUser, - GetSimklLoggedInUser + GetSimklLoggedInUser, LogoutAniList, LogoutMyAnimeList, LogoutSimkl } from "../wailsjs/go/main/App"; import type { AniListCurrentUserWatchList, @@ -32,9 +32,12 @@ let isAniListPrimary: boolean let page: number let perPage: number + let aniWatchlist: AniListCurrentUserWatchList + aniListPrimary.subscribe(value => isAniListPrimary = value) watchListPage.subscribe(value => page = value) animePerPage.subscribe(value => perPage = value) + aniListWatchlist.subscribe(value => aniWatchlist = value) export function GetAniListSingleItemAndOpenModal(aniId: number, login: boolean): void { GetAniListItem(aniId, login).then(result => { @@ -73,4 +76,31 @@ malLoggedIn.set(true) }) } + + export function logoutOfAniList(): void { + LogoutAniList().then(result => { + console.log(result) + if (Object.keys(aniWatchlist).length !== 0) { + aniListWatchlist.set({} as AniListCurrentUserWatchList) + } + aniListUser.set({} as AniListUser) + aniListLoggedIn.set(false) + }) + } + + export function logoutOfMAL(): void { + LogoutMyAnimeList().then(result => { + console.log(result) + malUser.set({} as MyAnimeListUser) + malLoggedIn.set(false) + }) + } + + export function logoutOfSimkl(): void { + LogoutSimkl().then(result => { + console.log(result) + simklUser.set({} as SimklUser) + simklLoggedIn.set(false) + }) + } \ No newline at end of file