diff --git a/theseus_gui/src/components/ui/platform/AccountDropdown.vue b/theseus_gui/src/components/ui/platform/AccountDropdown.vue index 8f1bdd9d5..626d80a7a 100644 --- a/theseus_gui/src/components/ui/platform/AccountDropdown.vue +++ b/theseus_gui/src/components/ui/platform/AccountDropdown.vue @@ -1,10 +1,18 @@ - diff --git a/theseus_gui/src/composables/auth.js b/theseus_gui/src/composables/auth.js new file mode 100644 index 000000000..3184f37c7 --- /dev/null +++ b/theseus_gui/src/composables/auth.js @@ -0,0 +1,38 @@ +import { ref, onMounted } from 'vue' +import { get as getCredentials, logout as removeCredentials } from '@/helpers/mr_auth.js' +import { handleError } from '@/store/state.js' + +export const useMrAuth = () => { + const auth = ref(null) + + const get = async () => { + try { + const creds = await getCredentials() + auth.value = creds + return creds + } catch (error) { + handleError(error) + } + } + + const logout = async () => { + try { + const result = await removeCredentials() + auth.value = null + return result + } catch (error) { + handleError(error) + } + return null + } + + onMounted(() => { + get() + }) + + return { + auth, + get, + logout, + } +} diff --git a/theseus_gui/src/pages/Settings.vue b/theseus_gui/src/pages/Settings.vue index e9d0370cc..0de945ff0 100644 --- a/theseus_gui/src/pages/Settings.vue +++ b/theseus_gui/src/pages/Settings.vue @@ -16,7 +16,9 @@ import { import { handleError, useTheming } from '@/store/state' import { is_dir_writeable, change_config_dir, get, set } from '@/helpers/settings' import { get_max_memory } from '@/helpers/jre' -import { get as getCreds, logout } from '@/helpers/mr_auth.js' + +import { useMrAuth } from '@/composables/auth' + import JavaSelector from '@/components/ui/JavaSelector.vue' import ModrinthLoginScreen from '@/components/ui/tutorial/ModrinthLoginScreen.vue' import { mixpanel_opt_out_tracking, mixpanel_opt_in_tracking } from '@/helpers/mixpanel' @@ -105,17 +107,12 @@ watch( { deep: true } ) -const credentials = ref(await getCreds().catch(handleError)) +const mrAuth = useMrAuth() const loginScreenModal = ref() -async function logOut() { - await logout().catch(handleError) - credentials.value = await getCreds().catch(handleError) -} - async function signInAfter() { loginScreenModal.value.hide() - credentials.value = await getCreds().catch(handleError) + await mrAuth.get() } async function findLauncherDir() { @@ -163,12 +160,12 @@ async function refreshDir() {
-