fix: use `masto.loginTo` to update masto api (#474)

pull/477/head
Daniel Roe 2022-12-20 15:56:54 +00:00 zatwierdzone przez GitHub
rodzic ab4321ad33
commit 60a8673757
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
8 zmienionych plików z 19 dodań i 14 usunięć

Wyświetl plik

@ -5,7 +5,7 @@ setupPageHeader()
provideGlobalCommands()
// We want to trigger rerendering the page when account changes
const key = computed(() => `${currentServer.value}:${currentUser.value?.account.id || ''}`)
const key = computed(() => `${currentUser.value?.server ?? currentServer.value}:${currentUser.value?.account.id || ''}`)
</script>
<template>

Wyświetl plik

@ -4,11 +4,12 @@ import type { UserLogin } from '~/types'
const all = useUsers()
const router = useRouter()
const masto = useMasto()
const switchUser = (user: UserLogin) => {
if (user.account.id === currentUser.value?.account.id)
router.push(getAccountRoute(user.account))
else
loginTo(user)
masto.loginTo(user)
}
</script>

Wyświetl plik

@ -15,11 +15,12 @@ const sorted = computed(() => {
})
const router = useRouter()
const masto = useMasto()
const switchUser = (user: UserLogin) => {
if (user.account.id === currentUser.value?.account.id)
router.push(getAccountRoute(user.account))
else
loginTo(user)
masto.loginTo(user)
}
</script>

Wyświetl plik

@ -204,6 +204,7 @@ export const provideGlobalCommands = () => {
const { locale, t } = useI18n()
const { locales } = useI18n() as { locales: ComputedRef<LocaleObject[]> }
const users = useUsers()
const masto = useMasto()
useCommand({
scope: 'Actions',
@ -299,7 +300,7 @@ export const provideGlobalCommands = () => {
icon: 'i-ri:user-shared-line',
onActivate() {
loginTo(user)
masto.loginTo(user)
},
})))
useCommand({

Wyświetl plik

@ -133,6 +133,8 @@ export async function signout() {
if (!currentUser.value)
return
const masto = useMasto()
const _currentUserId = currentUser.value.account.id
const index = users.value.findIndex(u => u.account?.id === _currentUserId)
@ -156,7 +158,7 @@ export async function signout() {
if (!currentUserId.value)
await useRouter().push('/')
await loginTo(currentUser.value)
await masto.loginTo(currentUser.value)
}
const notifications = reactive<Record<string, undefined | [Promise<WsEvents>, number]>>({})

Wyświetl plik

@ -18,11 +18,12 @@ const defaultMessage = 'Something went wrong'
const message = error.message ?? errorCodes[error.statusCode!] ?? defaultMessage
const state = ref<'error' | 'reloading'>('error')
const masto = useMasto()
const reload = async () => {
state.value = 'reloading'
try {
if (!useMasto())
await loginTo(currentUser.value)
if (!masto.loggedIn.value)
await masto.loginTo(currentUser.value)
clearError({ redirect: currentUser.value ? '/home' : `/${currentServer.value}/public` })
}
catch {

Wyświetl plik

@ -2,8 +2,10 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
if (process.server)
return
const masto = useMasto()
// Skip running middleware before masto has been initialised
if (!useNuxtApp().$masto)
if (!masto)
return
if (!('server' in to.params))
@ -13,7 +15,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
if (!user) {
if (from.params.server !== to.params.server) {
await loginTo({
await masto.loginTo({
server: to.params.server as string,
})
}
@ -47,7 +49,6 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
return getAccountRoute(account)
}
const masto = useMasto()
if (!masto.loggedIn.value)
await masto.loginTo(currentUser.value)

Wyświetl plik

@ -10,10 +10,8 @@ definePageMeta({
if (hasProtocol(permalink)) {
const { host, pathname } = parseURL(permalink)
if (host) {
await loginTo({ server: host })
return pathname
}
if (host)
return `/${host}${pathname}`
}
// We've reached a page that doesn't exist