diff --git a/components/user/UserSignIn.vue b/components/user/UserSignIn.vue index d9653cda..44b09dd1 100644 --- a/components/user/UserSignIn.vue +++ b/components/user/UserSignIn.vue @@ -3,16 +3,45 @@ import { DEFAULT_SERVER } from '~/constants' const input = $ref() let server = $ref('') +let busy = $ref(false) +let error = $ref(false) +let displayError = $ref(false) async function oauth() { + if (busy) + return + + busy = true + error = false + displayError = false + + await nextTick() + if (server) server = server.split('/')[0] - location.href = `/api/${server || DEFAULT_SERVER}/login` + + try { + location.href = await $fetch(`/api/${server || DEFAULT_SERVER}/login`) + } + catch { + displayError = true + error = true + await nextTick() + input?.focus() + await nextTick() + setTimeout(() => { + busy = false + error = false + }, 512) + } } async function handleInput() { if (server.startsWith('https://')) server = server.replace('https://', '') + + if (server?.length) + displayError = false } onMounted(() => { @@ -28,10 +57,31 @@ onMounted(() => { {{ $t('action.sign_in') }} -
{{ $t('user.server_address_label') }}
-
- https:// - +
+ {{ $t('user.server_address_label') }} +
+
+
+ https:// + +
+
+ +

+ {{ $t('error.sign_in_error') }} +

+
+
@@ -41,7 +91,8 @@ onMounted(() => {
- diff --git a/locales/en-US.json b/locales/en-US.json index 662cfa92..957a9a91 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -74,6 +74,7 @@ "error": { "account_not_found": "Account {0} not found", "explore-list-empty": "Nothing is trending right now. Check back later!", + "sign_in_error": "Cannot connect to the server.", "status_not_found": "Status not found" }, "feature_flag": { diff --git a/locales/es-ES.json b/locales/es-ES.json index ef2fe170..3c63860e 100644 --- a/locales/es-ES.json +++ b/locales/es-ES.json @@ -72,6 +72,8 @@ }, "error": { "account_not_found": "No se encontró la cuenta {0}", + "explore-list-empty": "Nada es tendencia en este momento. ¡Vuelva más tarde!", + "sign_in_error": "No se ha podido conectar con el servidor.", "status_not_found": "Estado no encontrado" }, "feature_flag": { diff --git a/server/api/[server]/login.ts b/server/api/[server]/login.ts index 4636c8cc..3141f31a 100644 --- a/server/api/[server]/login.ts +++ b/server/api/[server]/login.ts @@ -18,7 +18,6 @@ export default defineEventHandler(async (event) => { redirect_uri: getRedirectURI(server), response_type: 'code', }) - const url = `https://${server}/oauth/authorize?${query}` - await sendRedirect(event, url, 302) + return `https://${server}/oauth/authorize?${query}` })