mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-21 17:05:22 +03:00
fix: use masto.loginTo
to update masto api (#474)
This commit is contained in:
parent
ab4321ad33
commit
60a8673757
8 changed files with 19 additions and 14 deletions
2
app.vue
2
app.vue
|
@ -5,7 +5,7 @@ setupPageHeader()
|
||||||
provideGlobalCommands()
|
provideGlobalCommands()
|
||||||
|
|
||||||
// We want to trigger rerendering the page when account changes
|
// 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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -4,11 +4,12 @@ import type { UserLogin } from '~/types'
|
||||||
const all = useUsers()
|
const all = useUsers()
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const masto = useMasto()
|
||||||
const switchUser = (user: UserLogin) => {
|
const switchUser = (user: UserLogin) => {
|
||||||
if (user.account.id === currentUser.value?.account.id)
|
if (user.account.id === currentUser.value?.account.id)
|
||||||
router.push(getAccountRoute(user.account))
|
router.push(getAccountRoute(user.account))
|
||||||
else
|
else
|
||||||
loginTo(user)
|
masto.loginTo(user)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,12 @@ const sorted = computed(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const masto = useMasto()
|
||||||
const switchUser = (user: UserLogin) => {
|
const switchUser = (user: UserLogin) => {
|
||||||
if (user.account.id === currentUser.value?.account.id)
|
if (user.account.id === currentUser.value?.account.id)
|
||||||
router.push(getAccountRoute(user.account))
|
router.push(getAccountRoute(user.account))
|
||||||
else
|
else
|
||||||
loginTo(user)
|
masto.loginTo(user)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -204,6 +204,7 @@ export const provideGlobalCommands = () => {
|
||||||
const { locale, t } = useI18n()
|
const { locale, t } = useI18n()
|
||||||
const { locales } = useI18n() as { locales: ComputedRef<LocaleObject[]> }
|
const { locales } = useI18n() as { locales: ComputedRef<LocaleObject[]> }
|
||||||
const users = useUsers()
|
const users = useUsers()
|
||||||
|
const masto = useMasto()
|
||||||
|
|
||||||
useCommand({
|
useCommand({
|
||||||
scope: 'Actions',
|
scope: 'Actions',
|
||||||
|
@ -299,7 +300,7 @@ export const provideGlobalCommands = () => {
|
||||||
icon: 'i-ri:user-shared-line',
|
icon: 'i-ri:user-shared-line',
|
||||||
|
|
||||||
onActivate() {
|
onActivate() {
|
||||||
loginTo(user)
|
masto.loginTo(user)
|
||||||
},
|
},
|
||||||
})))
|
})))
|
||||||
useCommand({
|
useCommand({
|
||||||
|
|
|
@ -133,6 +133,8 @@ export async function signout() {
|
||||||
if (!currentUser.value)
|
if (!currentUser.value)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
const masto = useMasto()
|
||||||
|
|
||||||
const _currentUserId = currentUser.value.account.id
|
const _currentUserId = currentUser.value.account.id
|
||||||
|
|
||||||
const index = users.value.findIndex(u => u.account?.id === _currentUserId)
|
const index = users.value.findIndex(u => u.account?.id === _currentUserId)
|
||||||
|
@ -156,7 +158,7 @@ export async function signout() {
|
||||||
if (!currentUserId.value)
|
if (!currentUserId.value)
|
||||||
await useRouter().push('/')
|
await useRouter().push('/')
|
||||||
|
|
||||||
await loginTo(currentUser.value)
|
await masto.loginTo(currentUser.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
const notifications = reactive<Record<string, undefined | [Promise<WsEvents>, number]>>({})
|
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 message = error.message ?? errorCodes[error.statusCode!] ?? defaultMessage
|
||||||
|
|
||||||
const state = ref<'error' | 'reloading'>('error')
|
const state = ref<'error' | 'reloading'>('error')
|
||||||
|
const masto = useMasto()
|
||||||
const reload = async () => {
|
const reload = async () => {
|
||||||
state.value = 'reloading'
|
state.value = 'reloading'
|
||||||
try {
|
try {
|
||||||
if (!useMasto())
|
if (!masto.loggedIn.value)
|
||||||
await loginTo(currentUser.value)
|
await masto.loginTo(currentUser.value)
|
||||||
clearError({ redirect: currentUser.value ? '/home' : `/${currentServer.value}/public` })
|
clearError({ redirect: currentUser.value ? '/home' : `/${currentServer.value}/public` })
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
|
|
@ -2,8 +2,10 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||||
if (process.server)
|
if (process.server)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
const masto = useMasto()
|
||||||
|
|
||||||
// Skip running middleware before masto has been initialised
|
// Skip running middleware before masto has been initialised
|
||||||
if (!useNuxtApp().$masto)
|
if (!masto)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (!('server' in to.params))
|
if (!('server' in to.params))
|
||||||
|
@ -13,7 +15,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
if (from.params.server !== to.params.server) {
|
if (from.params.server !== to.params.server) {
|
||||||
await loginTo({
|
await masto.loginTo({
|
||||||
server: to.params.server as string,
|
server: to.params.server as string,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -47,7 +49,6 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||||
return getAccountRoute(account)
|
return getAccountRoute(account)
|
||||||
}
|
}
|
||||||
|
|
||||||
const masto = useMasto()
|
|
||||||
if (!masto.loggedIn.value)
|
if (!masto.loggedIn.value)
|
||||||
await masto.loginTo(currentUser.value)
|
await masto.loginTo(currentUser.value)
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,8 @@ definePageMeta({
|
||||||
if (hasProtocol(permalink)) {
|
if (hasProtocol(permalink)) {
|
||||||
const { host, pathname } = parseURL(permalink)
|
const { host, pathname } = parseURL(permalink)
|
||||||
|
|
||||||
if (host) {
|
if (host)
|
||||||
await loginTo({ server: host })
|
return `/${host}${pathname}`
|
||||||
return pathname
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We've reached a page that doesn't exist
|
// We've reached a page that doesn't exist
|
||||||
|
|
Loading…
Reference in a new issue