feat: add shared UI package auth DI

This commit is contained in:
tdgao
2026-03-31 00:15:32 -06:00
parent 90deb7310e
commit d401f1183e
5 changed files with 57 additions and 1 deletions
+17 -1
View File
@@ -40,6 +40,7 @@ import {
OverflowMenu,
PopupNotificationPanel,
ProgressSpinner,
provideAuth,
provideModalBehavior,
provideModrinthClient,
provideNotificationManager,
@@ -57,7 +58,7 @@ import { openUrl } from '@tauri-apps/plugin-opener'
import { type } from '@tauri-apps/plugin-os'
import { saveWindowState, StateFlags } from '@tauri-apps/plugin-window-state'
import { $fetch } from 'ofetch'
import { computed, onMounted, onUnmounted, provide, ref, watch } from 'vue'
import { computed, onMounted, onUnmounted, provide, reactive, ref, watch, watchEffect } from 'vue'
import { RouterView, useRoute, useRouter } from 'vue-router'
import ModrinthAppLogo from '@/assets/modrinth_app.svg?component'
@@ -454,6 +455,21 @@ const credentials = ref()
const modrinthLoginFlowWaitModal = ref()
const authProvider = reactive({
session_token: null,
user: null,
requestSignIn: async (_redirectPath) => {
await signIn()
},
})
watchEffect(() => {
authProvider.session_token = credentials.value?.session ?? null
authProvider.user = credentials.value?.user ?? null
})
provideAuth(authProvider)
async function fetchCredentials() {
const creds = await getCreds().catch(handleError)
if (creds && creds.user_id) {