mirror of
https://github.com/elk-zone/elk
synced 2024-11-27 06:18:07 +09:00
fix: use masto.loginTo
to update masto api (#474)
This commit is contained in:
parent
ab4321ad33
commit
60a8673757
2
app.vue
2
app.vue
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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({
|
||||
|
@ -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]>>({})
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user