feat: add shared UI package auth DI (#5720)

* feat: add shared UI package auth DI

* use refs instead of reactive

* pnpm prepr

* move app auth provider setup to src/providers/setup
This commit is contained in:
Truman Gao
2026-03-31 10:15:35 -07:00
committed by GitHub
parent e2bfed177d
commit 4224ef45b3
6 changed files with 78 additions and 0 deletions

View File

@@ -106,6 +106,7 @@ import {
} from '@/providers/download-progress.ts'
import { createServerInstall, provideServerInstall } from '@/providers/server-install'
import { setupProviders } from '@/providers/setup'
import { setupAuthProvider } from '@/providers/setup/auth'
import { useError } from '@/store/error.js'
import { useLoading, useTheming } from '@/store/state'
@@ -454,6 +455,10 @@ const credentials = ref()
const modrinthLoginFlowWaitModal = ref()
setupAuthProvider(credentials, async (_redirectPath) => {
await signIn()
})
async function fetchCredentials() {
const creds = await getCreds().catch(handleError)
if (creds && creds.user_id) {

View File

@@ -0,0 +1,29 @@
import type { Labrinth } from '@modrinth/api-client'
import { type AuthProvider, provideAuth } from '@modrinth/ui'
import { type Ref, ref, watchEffect } from 'vue'
type AppCredentials = {
session?: string | null
user?: Labrinth.Users.v2.User | null
}
export function setupAuthProvider(
credentials: Ref<AppCredentials | null | undefined>,
requestSignIn: (redirectPath: string) => void | Promise<void>,
) {
const sessionToken = ref<string | null>(null)
const user = ref<Labrinth.Users.v2.User | null>(null)
const authProvider: AuthProvider = {
session_token: sessionToken,
user,
requestSignIn,
}
watchEffect(() => {
sessionToken.value = credentials.value?.session ?? null
user.value = credentials.value?.user ?? null
})
provideAuth(authProvider)
}