@@ -25,7 +25,7 @@
@@ -98,38 +108,27 @@ onMounted(async () => {
\ No newline at end of file
diff --git a/composables/auth.ts b/composables/auth.ts
index 19ac694..ccb45ca 100644
--- a/composables/auth.ts
+++ b/composables/auth.ts
@@ -30,11 +30,11 @@ export const useAuth = () => {
{
username, password: hashedPass, device_name: "Linux Laptop"
}
- }) as { access_token: string, refresh_token: string };
+ }) as { access_token: string, refresh_token: string }; fetch
console.log("hi");
accessToken.value = res.access_token;
console.log("access token:", accessToken.value);
- //await fetchUser();
+ await fetchUser();
}
async function logout(password: string) {
@@ -60,21 +60,19 @@ export const useAuth = () => {
async function refresh() {
console.log("refreshing");
- const res = await fetchWithApi("/auth/refresh", {
- method: "POST"
- }) as any;
- console.log("finished refreshing:", res);
- if (res && res.access_token) {
+ try {
+ const res = await fetchWithApi("/auth/refresh", {
+ method: "POST"
+ }) as { access_token: string };
accessToken.value = res.access_token;
console.log("set new access token");
- } else {
- console.log("refresh didn't return access token");
+ } catch (error) {
+ console.error("refresh error:", error);
}
}
async function fetchUser() {
if (!accessToken.value) return;
- console.log("fetchuser access token:", accessToken.value);
const res = await fetchWithApi("/users/me") as UserResponse;
user.value = res;
return user.value;
diff --git a/error.vue b/error.vue
deleted file mode 100644
index dff8c5f..0000000
--- a/error.vue
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
{{ error?.statusCode }}
-
{{ error?.message }}
-
-
-
-
-
-
diff --git a/layouts/auth.vue b/layouts/auth.vue
index 356dcd5..f90dc84 100644
--- a/layouts/auth.vue
+++ b/layouts/auth.vue
@@ -1,6 +1,7 @@
-
+
+
{{ instanceError }}
@@ -48,6 +49,7 @@
-
-
\ No newline at end of file
diff --git a/pages/login.vue b/pages/login.vue
index 4ae6de3..485166d 100644
--- a/pages/login.vue
+++ b/pages/login.vue
@@ -1,60 +1,46 @@
-
-
-
- Don't have an account? Register one!
-
-
+
+
+
+ Don't have an account? Register one!
+
+
diff --git a/pages/register.vue b/pages/register.vue
index 73d0920..cd17005 100644
--- a/pages/register.vue
+++ b/pages/register.vue
@@ -33,7 +33,7 @@
- Already have an account? Log in!
+ Already have an account? Log in!
@@ -74,9 +74,7 @@ const errorMessages = reactive({
//const authStore = useAuthStore();
const auth = useAuth();
-const query = useRoute().query as Record
;
-const searchParams = new URLSearchParams(query);
-const loginUrl = `/login?${searchParams}`
+const redirectTo = useRoute().query.redirect_to;
onMounted(() => {
if (auth.accessToken.value) {
@@ -122,12 +120,7 @@ const apiVersion = useRuntimeConfig().public.apiVersion;
async function register(e: Event) {
e.preventDefault();
console.log("Sending registration data");
- try {
- await auth.register(form.username, form.email, form.password);
- return await navigateTo(query.redirect_to);
- } catch (error) {
- console.error("Error registering:", error);
- }
+ await auth.register(form.username, form.email, form.password);
//return navigateTo(redirectTo ? redirectTo as string : useAppConfig().baseURL as string);
}
diff --git a/pages/servers/[serverId]/channels/[channelId].vue b/pages/servers/[serverId]/channels/[channelId].vue
index eb6ba46..efa2858 100644
--- a/pages/servers/[serverId]/channels/[channelId].vue
+++ b/pages/servers/[serverId]/channels/[channelId].vue
@@ -39,20 +39,25 @@
const route = useRoute();
-const loading = useState("loading");
+const server: GuildResponse | undefined = await fetchWithApi(`servers/${route.params.serverId}`);
+
+const channels: ChannelResponse[] | undefined = await fetchWithApi(
+ `servers/${route.params.serverId}/channels`
+);
+const channel: ChannelResponse | undefined = await fetchWithApi(
+ route.path
+);
const channelUrlPath = `servers/${route.params.serverId}/channels/${route.params.channelId}`;
-const server = ref();
-const channels = ref();
-const channel = ref();
+console.log("channel:", channel);
const showInvitePopup = ref(false);
import type { ChannelResponse, GuildResponse, MessageResponse } from "~/types/interfaces";
//const servers = await fetchWithApi("/servers") as { uuid: string, name: string, description: string }[];
-//console.log("channelid: servers:", servers);
+//console.log("servers:", servers);
const members = [
{
id: "3287484395",
@@ -101,23 +106,6 @@ const members = [
}
];
-onMounted(async () => {
- loading.value = true;
- console.log("channelid: set loading to true");
- server.value = await fetchWithApi(`servers/${route.params.serverId}`);
-
- channels.value = await fetchWithApi(
- `servers/${route.params.serverId}/channels`
- );
- channel.value = await fetchWithApi(
- route.path
- );
-
- console.log("channelid: channel:", channel);
- loading.value = false;
- console.log("channelid: set loading to false");
-});
-
function showServerSettings() { }
function toggleInvitePopup(e: Event) {
diff --git a/pages/verify-email.vue b/pages/verify-email.vue
deleted file mode 100644
index cae02ea..0000000
--- a/pages/verify-email.vue
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
- {{ errorMessage }}
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/types/interfaces.ts b/types/interfaces.ts
index c0c87a9..05830d2 100644
--- a/types/interfaces.ts
+++ b/types/interfaces.ts
@@ -32,11 +32,10 @@ export interface ChannelResponse {
}
export interface MessageResponse {
- uuid: string,
- channel_uuid: string,
- user_uuid: string,
- message: string,
- user: UserResponse
+ uuid: string
+ channel_uuid: string
+ user_uuid: string
+ message: string
}
export interface InviteResponse {
@@ -50,6 +49,6 @@ export interface UserResponse {
username: string,
display_name: string | null,
avatar: string | null,
- email?: string,
- email_verified?: boolean
+ email: string,
+ email_verified: boolean
}
diff --git a/utils/fetchWithApi.ts b/utils/fetchWithApi.ts
index 79fdae8..c0ebf2e 100644
--- a/utils/fetchWithApi.ts
+++ b/utils/fetchWithApi.ts
@@ -9,74 +9,63 @@ export default async (path: string, options: NitroFetchOptions = {})
path = path.slice(0, path.lastIndexOf("/"));
}
console.log("formatted path:", path);
- const accessToken = useCookie("access_token");
- console.log("access token:", accessToken.value);
- const apiBase = useCookie("api_base").value;
- const apiVersion = useRuntimeConfig().public.apiVersion;
- console.log("heyoooo")
- console.log("apiBase:", apiBase);
- if (!apiBase) {
- console.log("no api base");
- return;
- }
- console.log("path:", path)
- const { revoke, refresh } = useAuth();
- console.log("access token 2:", accessToken.value);
-
- let headers: HeadersInit = {};
-
- if (accessToken.value) {
- headers = {
- ...options.headers,
- "Authorization": `Bearer ${accessToken.value}`
- };
- } else {
- headers = {
- ...options.headers
- };
- }
-
- let reauthFailed = false;
- while (!reauthFailed) {
- try {
- console.log("fetching:", URL.parse(apiBase + path));
- const res = await $fetch(URL.parse(apiBase + path)!.href, {
- ...options,
- headers,
- credentials: "include"
- });
-
- return res;
- } catch (error: any) {
- console.error("Error fetching resource");
- if (error?.response?.status === 401) {
- console.log("Error status is 401");
- if (!path.startsWith("/auth/refresh")) {
- console.log("Path is not refresh endpoint");
- try {
- console.log("Trying to refresh");
- await refresh();
- console.log("Successfully refreshed token");
- } catch (error: any) {
- console.log("Failed to refresh token");
- if (error?.response?.status === 401) {
- console.log("Refresh returned 401");
- reauthFailed = true;
- console.log("Revoking");
- await revoke();
- console.log("Redirecting to login");
- await navigateTo("/login");
- console.log("redirected");
- return;
+ try {
+ const accessToken = useCookie("access_token");
+ console.log("access token:", accessToken.value);
+ const apiBase = useCookie("api_base").value;
+ const apiVersion = useRuntimeConfig().public.apiVersion;
+ console.log("heyoooo")
+ console.log("apiBase:", apiBase);
+ if (!apiBase) {
+ console.log("no api base");
+ return;
+ }
+ console.log("path:", path)
+ const { revoke, refresh } = useAuth();
+ console.log("access token 2:", accessToken.value);
+
+ let headers: HeadersInit = {};
+
+ if (accessToken.value) {
+ headers = {
+ ...options.headers,
+ "Authorization": `Bearer ${accessToken.value}`
+ };
+ } else {
+ headers = {
+ ...options.headers
+ };
+ }
+
+ let reauthFailed = false;
+ while (!reauthFailed) {
+ try {
+ console.log("fetching:", URL.parse(apiBase + path));
+ const res = await $fetch(URL.parse(apiBase + path)!.href, {
+ ...options,
+ headers,
+ credentials: "include"
+ });
+
+ return res;
+ } catch (error: any) {
+ if (error?.response?.status === 401) {
+ if (!path.startsWith("/auth/refresh")) {
+ try {
+ await refresh();
+ } catch (error: any) {
+ if (error?.response?.status === 401) {
+ reauthFailed = true;
+ await revoke();
+ return;
+ }
}
}
- } else {
- console.log("Path is refresh endpoint, throwing error");
- throw error;
}
+ throw error;
}
- console.log("throwing error");
- throw error;
}
+ } catch (error) {
+ console.error("error:", error);
}
}
diff --git a/utils/scrollToBottom.ts b/utils/scrollToBottom.ts
deleted file mode 100644
index aca99b4..0000000
--- a/utils/scrollToBottom.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export default (element: Ref) => {
- if (element.value) {
- element.value.scrollTo({ top: element.value.scrollHeight });
- return;
- }
-}