feat: prevent mixing data on account switch (#384)
This commit is contained in:
parent
8c82c91056
commit
de160c219a
5 changed files with 42 additions and 26 deletions
|
@ -31,12 +31,6 @@ export const currentInstance = computed<null | Instance>(() => currentUserId.val
|
|||
export const characterLimit = computed(() => currentInstance.value?.configuration.statuses.maxCharacters ?? DEFAULT_POST_CHARS_LIMIT)
|
||||
|
||||
export async function loginTo(user?: Omit<UserLogin, 'account'> & { account?: AccountCredentials }) {
|
||||
if (user) {
|
||||
const existing = users.value.find(u => u.server === user.server && u.token === user.token)
|
||||
if (existing && currentUserId.value !== user.account?.id)
|
||||
currentUserId.value = user.account?.id
|
||||
}
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
@ -76,7 +70,7 @@ export async function loginTo(user?: Omit<UserLogin, 'account'> & { account?: Ac
|
|||
|
||||
setMasto(masto)
|
||||
|
||||
if ('server' in route.params) {
|
||||
if ('server' in route.params && user?.token) {
|
||||
await router.push({
|
||||
...route,
|
||||
force: true,
|
||||
|
@ -110,7 +104,7 @@ export async function signout() {
|
|||
currentUserId.value = users.value[0]?.account?.id
|
||||
|
||||
if (!currentUserId.value)
|
||||
await useRouter().push(`/${currentServer.value}/public`)
|
||||
await useRouter().push('/')
|
||||
|
||||
await loginTo(currentUser.value)
|
||||
}
|
||||
|
@ -127,7 +121,7 @@ export const useNotifications = () => {
|
|||
}
|
||||
|
||||
async function connect(): Promise<void> {
|
||||
if (!id || notifications[id])
|
||||
if (!id || notifications[id] || !currentUser.value?.token)
|
||||
return
|
||||
|
||||
const masto = useMasto()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue