feat: custom error page (#178)

Co-authored-by: Daniel Roe <daniel@roe.dev>
This commit is contained in:
Joaquín Sánchez 2022-11-28 10:01:14 +01:00 committed by GitHub
parent b8cadca717
commit 3b92b27cc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 106 additions and 42 deletions

View file

@ -2,6 +2,7 @@ import type { MastoClient } from 'masto'
import { currentUser } from '../composables/users'
export default defineNuxtPlugin(async () => {
let masto!: MastoClient
try {
const { query } = useRoute()
const user = typeof query.server === 'string' && typeof query.token === 'string'
@ -9,23 +10,22 @@ export default defineNuxtPlugin(async () => {
: currentUser.value
// TODO: improve upstream to make this synchronous (delayed auth)
const masto = await loginTo(user) as MastoClient
return {
provide: {
masto: shallowReactive({
replace(api: MastoClient) { this.api = api },
api: masto,
}),
},
}
masto = await loginTo(user)
}
catch {
// TODO: handle error
// Show error page when Mastodon server is down
throw createError({
showError({
fatal: true,
statusMessage: 'Could not log into account.',
})
}
return {
provide: {
masto: shallowReactive({
replace(api: MastoClient) { this.api = api },
api: masto,
}),
},
}
})