fix: registration and registration detection handling
This commit is contained in:
parent
febdbb9421
commit
038b1af44e
3 changed files with 34 additions and 25 deletions
|
@ -51,29 +51,17 @@
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { FetchError } from 'ofetch';
|
import { FetchError } from 'ofetch';
|
||||||
|
import type { StatsResponse } from '~/types/interfaces';
|
||||||
|
|
||||||
const instanceUrl = ref<string | null | undefined>(null);
|
const instanceUrl = ref<string | null | undefined>(null);
|
||||||
const instanceUrlInput = ref<string>();
|
const instanceUrlInput = ref<string>();
|
||||||
const instanceError = ref<string>();
|
const instanceError = ref<string>();
|
||||||
const requestUrl = useRequestURL();
|
|
||||||
const apiVersion = useRuntimeConfig().public.apiVersion;
|
const apiVersion = useRuntimeConfig().public.apiVersion;
|
||||||
const apiBase = useCookie("api_base");
|
const apiBase = useCookie("api_base");
|
||||||
const gorbTxtError = ref<string>("");
|
const registrationEnabled = useState("registrationEnabled", () => true);
|
||||||
|
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
|
|
||||||
const { status, data: gorbTxt } = await useFetch(`${requestUrl.protocol}//${requestUrl.host}/.well-known/gorb.txt`, { responseType: "text" });
|
|
||||||
if (status.value == "success" && gorbTxt.value) {
|
|
||||||
console.log("got gorb.txt:", gorbTxt.value);
|
|
||||||
const parsed = parseWellKnown(gorbTxt.value as string);
|
|
||||||
if (parsed.ApiBaseUrl) {
|
|
||||||
apiBase.value = `${parsed.ApiBaseUrl}/${apiVersion}`;
|
|
||||||
console.log("set apiBase to:", parsed.ApiBaseUrl);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
gorbTxtError.value = "Failed to find that instance.";
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const cookie = useCookie("instance_url").value;
|
const cookie = useCookie("instance_url").value;
|
||||||
instanceUrl.value = cookie;
|
instanceUrl.value = cookie;
|
||||||
|
@ -99,6 +87,11 @@ async function selectInstance(e: Event) {
|
||||||
instanceUrl.value = origin;
|
instanceUrl.value = origin;
|
||||||
useCookie("instance_url").value = origin;
|
useCookie("instance_url").value = origin;
|
||||||
console.log("set instance url to:", origin);
|
console.log("set instance url to:", origin);
|
||||||
|
const { status, data, error } = await useFetch<StatsResponse>(`${apiBase.value}/stats`);
|
||||||
|
if (status.value == "success" && data.value) {
|
||||||
|
registrationEnabled.value = data.value.registration_enabled;
|
||||||
|
console.log("set registration enabled value to:", data.value.registration_enabled);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
instanceError.value = "That URL is not a valid instance.";
|
instanceError.value = "That URL is not a valid instance.";
|
||||||
|
|
|
@ -3,6 +3,25 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||||
const loading = useState("loading");
|
const loading = useState("loading");
|
||||||
const accessToken = useCookie("access_token").value;
|
const accessToken = useCookie("access_token").value;
|
||||||
if (["/login", "/register"].includes(to.path)) {
|
if (["/login", "/register"].includes(to.path)) {
|
||||||
|
console.log("path is login or register");
|
||||||
|
const apiBase = useCookie("api_base");
|
||||||
|
console.log("apiBase gotten:", apiBase.value);
|
||||||
|
if (!apiBase.value) {
|
||||||
|
const requestUrl = useRequestURL();
|
||||||
|
console.log("request url:", requestUrl.href);
|
||||||
|
const apiVersion = useRuntimeConfig().public.apiVersion;
|
||||||
|
console.log("api version:", apiVersion);
|
||||||
|
console.log("apiBase not set");
|
||||||
|
const { status, data: gorbTxt } = await useFetch(`${requestUrl.protocol}//${requestUrl.host}/.well-known/gorb.txt`, { responseType: "text" });
|
||||||
|
if (status.value == "success" && gorbTxt.value) {
|
||||||
|
console.log("got gorb.txt:", gorbTxt.value);
|
||||||
|
const parsed = parseWellKnown(gorbTxt.value as string);
|
||||||
|
if (parsed.ApiBaseUrl) {
|
||||||
|
apiBase.value = `${parsed.ApiBaseUrl}/${apiVersion}`;
|
||||||
|
console.log("set apiBase to:", parsed.ApiBaseUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
return await navigateTo("/");
|
return await navigateTo("/");
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,14 +47,17 @@ definePageMeta({
|
||||||
layout: "auth"
|
layout: "auth"
|
||||||
})
|
})
|
||||||
|
|
||||||
const instanceUrl = useCookie("instance_url").value;
|
const registrationEnabled = useState("registrationEnabled", () => true);
|
||||||
const registrationEnabled = ref<boolean>(false);
|
|
||||||
|
|
||||||
if (instanceUrl) {
|
console.log("wah");
|
||||||
const statsUrl = new URL("/stats", instanceUrl).href;
|
console.log("weoooo")
|
||||||
const { status, data, error } = await useFetch<StatsResponse>(statsUrl);
|
const apiBase = useCookie("api_base");
|
||||||
|
console.log("apiBase:", apiBase.value);
|
||||||
|
if (apiBase.value) {
|
||||||
|
const { status, data, error } = await useFetch<StatsResponse>(`${apiBase.value}/stats`);
|
||||||
if (status.value == "success" && data.value) {
|
if (status.value == "success" && data.value) {
|
||||||
registrationEnabled.value = data.value.registration_enabled;
|
registrationEnabled.value = data.value.registration_enabled;
|
||||||
|
console.log("set registration enabled value to:", data.value.registration_enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,12 +95,6 @@ const query = useRoute().query as Record<string, string>;
|
||||||
const searchParams = new URLSearchParams(query);
|
const searchParams = new URLSearchParams(query);
|
||||||
const loginUrl = `/login?${searchParams}`
|
const loginUrl = `/login?${searchParams}`
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
if (auth.accessToken.value) {
|
|
||||||
//return navigateTo(redirectTo ? redirectTo as string : useAppConfig().baseURL as string);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
watch(() => form.username, (newValue) => {
|
watch(() => form.username, (newValue) => {
|
||||||
console.log("username change:", newValue);
|
console.log("username change:", newValue);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue