diff --git a/components/Settings/UserSettings/Account.vue b/components/Settings/UserSettings/Account.vue index 5d76a0a..b2ac87a 100644 --- a/components/Settings/UserSettings/Account.vue +++ b/components/Settings/UserSettings/Account.vue @@ -43,6 +43,14 @@ async function changeEmail() { body: formData }) + const apiBase = useCookie("api_base").value; + + if (apiBase) { + const stats = await useApi().fetchInstanceStats(apiBase); + if (stats.email_verification_required) { + return window.location.reload(); + } + } alert('success!!') } catch (error: any) { if (error?.response?.status !== 200) { diff --git a/composables/api.ts b/composables/api.ts index 603f71f..d2ca7a0 100644 --- a/composables/api.ts +++ b/composables/api.ts @@ -1,4 +1,4 @@ -import type { ChannelResponse, GuildMemberResponse, GuildResponse, MessageResponse } from "~/types/interfaces"; +import type { ChannelResponse, GuildMemberResponse, GuildResponse, MessageResponse, StatsResponse } from "~/types/interfaces"; export const useApi = () => { async function fetchGuilds(): Promise { @@ -41,6 +41,15 @@ export const useApi = () => { return await fetchWithApi(`/channels/${channelId}/messages/${messageId}`); } + async function fetchInstanceStats(apiBase: string): Promise { + return await $fetch(`${apiBase}/stats`, { method: "GET" }); + } + + async function sendVerificationEmail(): Promise { + const email = useAuth().user.value?.email; + await fetchWithApi("/auth/verify-email", { method: "POST", body: { email } }); + } + return { fetchGuilds, fetchGuild, @@ -51,6 +60,8 @@ export const useApi = () => { fetchUsers, fetchUser, fetchMessages, - fetchMessage + fetchMessage, + fetchInstanceStats, + sendVerificationEmail } } diff --git a/composables/auth.ts b/composables/auth.ts index b23a67b..ebe27de 100644 --- a/composables/auth.ts +++ b/composables/auth.ts @@ -7,6 +7,7 @@ export const useAuth = () => { async function clearAuth() { accessToken.value = null; user.value = null; + await navigateTo("/login"); } async function register(username: string, email: string, password: string) { diff --git a/layouts/auth.vue b/layouts/auth.vue index b7d5c5e..0c4ad41 100644 --- a/layouts/auth.vue +++ b/layouts/auth.vue @@ -20,30 +20,7 @@
- Instance URL is set to {{ instanceUrl }} -
-
- You're logged in! -
-
- -
- -
-
- -
-
-
- -
-
- -
-
- -
+ Instance URL is set to {{ instanceUrl }}
@@ -51,7 +28,6 @@ \ No newline at end of file diff --git a/pages/verify-email.vue b/pages/verify-email.vue index cae02ea..f160a1d 100644 --- a/pages/verify-email.vue +++ b/pages/verify-email.vue @@ -15,6 +15,12 @@ const token = useRoute().query.token; try { const res = await fetchWithApi("/auth/verify-email", { query: { token } }); console.log("hi"); + const query = useRoute().query; + if (query.redirect_to) { + await navigateTo(`/?redirect_to=${query.redirect_to}`); + } else { + await navigateTo("/"); + } } catch (error) { console.error("Error verifying email:", error); errorMessage.value = error;