fix: auto logout on stale token (#144)

This commit is contained in:
Shinigami 2022-11-26 20:33:36 +01:00 committed by GitHub
parent 2d16c4868e
commit 94f2f95bcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 5 deletions

View file

@ -4,12 +4,17 @@ import { DEFAULT_SERVER } from '~/constants'
export default defineNuxtPlugin(async () => {
try {
const accessToken = currentUser.value?.token
// TODO: improve upstream to make this synchronous (delayed auth)
const masto = await login({
url: `https://${currentUser.value?.server || DEFAULT_SERVER}`,
accessToken: currentUser.value?.token || undefined,
accessToken,
})
if (accessToken)
masto.accounts.verifyCredentials().catch(() => signout())
return {
provide: {
masto,