From 29b4cb43ca5f5bebbe2ea8517793eb91078f90d2 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Wed, 29 Jan 2025 04:39:33 +0100 Subject: [PATCH] feat: :sparkles: Add support for accounts on other instances --- app.vue | 17 +++++++- components/modals/composable.ts | 2 +- components/modals/confirm.vue | 12 ++++-- components/sidebars/account-switcher.vue | 4 +- components/ui/input/index.ts | 1 + components/ui/input/url.vue | 53 ++++++++++++++++++++++++ composables/CacheRefresh.ts | 2 +- composables/Client.ts | 33 ++++++++------- layouts/app.vue | 2 +- messages/en.json | 7 +++- messages/fr.json | 7 +++- pages/oauth/authorize.vue | 41 +++++++++++++++--- utils/auth.ts | 38 +++++++++++++---- 13 files changed, 179 insertions(+), 40 deletions(-) create mode 100644 components/ui/input/url.vue diff --git a/app.vue b/app.vue index d6a6802..782f713 100644 --- a/app.vue +++ b/app.vue @@ -27,6 +27,7 @@ const lang = useLanguage(); setLanguageTag(lang.value); const code = useRequestURL().searchParams.get("code"); +const origin = useRequestURL().searchParams.get("origin"); const appData = useAppData(); const instance = useInstance(); const description = useExtendedDescription(client); @@ -72,8 +73,20 @@ useHead({ }, }); -if (code && appData.value && route.path !== "/oauth/code") { - signInWithCode(code, appData.value); +if (code && origin && appData.value && route.path !== "/oauth/code") { + const newOrigin = new URL( + URL.canParse(origin) ? origin : `https://${origin}`, + ); + + signInWithCode(code, appData.value, newOrigin); +} + +if (origin && !code) { + const newOrigin = new URL( + URL.canParse(origin) ? origin : `https://${origin}`, + ); + + signIn(appData, newOrigin); } useListen("identity:change", (newIdentity) => { diff --git a/components/modals/composable.ts b/components/modals/composable.ts index ab64f5e..b9198b9 100644 --- a/components/modals/composable.ts +++ b/components/modals/composable.ts @@ -3,7 +3,7 @@ export type ConfirmModalOptions = { message?: string; confirmText?: string; cancelText?: string; - inputType?: "none" | "text" | "textarea"; + inputType?: "none" | "text" | "textarea" | "url"; defaultValue?: string; }; diff --git a/components/modals/confirm.vue b/components/modals/confirm.vue index 5d0019e..e3a4c85 100644 --- a/components/modals/confirm.vue +++ b/components/modals/confirm.vue @@ -10,7 +10,7 @@ import { AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; +import { Input, UrlInput } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import * as m from "~/paraglide/messages.js"; import { @@ -32,6 +32,8 @@ const resolvePromise = ref<((result: ConfirmModalResult) => void) | null>(null); function open(options: ConfirmModalOptions): Promise { isOpen.value = true; + isValid.value = false; + modalOptions.value = { title: options.title || m.antsy_whole_alligator_blink(), message: options.message, @@ -68,6 +70,8 @@ function handleCancel() { confirmModalService.register({ open, }); + +const isValid = ref(false);