Merge branch 'guild-settings' into guild-joining
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful

This commit is contained in:
SauceyRed 2025-07-13 01:44:43 +02:00
commit cf32b62ae7
Signed by: sauceyred
GPG key ID: 270B096EF6E9A462
67 changed files with 2621 additions and 255 deletions

View file

@ -1,4 +1,4 @@
import type { ChannelResponse, GuildMemberResponse, GuildResponse, MessageResponse } from "~/types/interfaces";
import type { ChannelResponse, GuildMemberResponse, GuildResponse, MessageResponse, StatsResponse, UserResponse } from "~/types/interfaces";
export const useApi = () => {
async function fetchGuilds(): Promise<GuildResponse[] | undefined> {
@ -24,14 +24,26 @@ export const useApi = () => {
async function fetchMember(guildId: string, memberId: string): Promise<GuildMemberResponse | undefined> {
return await fetchWithApi(`/guilds/${guildId}/members/${memberId}`);
}
async function fetchUsers() {
return await fetchWithApi(`/users`);
}
async function fetchUser(userId: string) {
return await fetchWithApi(`/users/${userId}`);
}
async function fetchFriends(): Promise<UserResponse[] | undefined> {
return await fetchWithApi('/me/friends')
}
async function addFriend(username: string): Promise<void> {
return await fetchWithApi('/me/friends', { method: "POST", body: { username } });
}
async function removeFriend(userId: string): Promise<void> {
return await fetchWithApi(`/me/friends/${userId}`, { method: "DELETE" });
}
async function fetchMessages(channelId: string, options?: { amount?: number, offset?: number }): Promise<MessageResponse[] | undefined> {
return await fetchWithApi(`/channels/${channelId}/messages`, { query: { amount: options?.amount ?? 100, offset: options?.offset ?? 0 } });
@ -52,6 +64,15 @@ export const useApi = () => {
async function createChannel(guildId: string, name: string, description?: string): Promise<void> {
return await fetchWithApi(`/guilds/${guildId}/channels`, { method: "POST", body: { name, description } });
}
async function fetchInstanceStats(apiBase: string): Promise<StatsResponse> {
return await $fetch(`${apiBase}/stats`, { method: "GET" });
}
async function sendVerificationEmail(): Promise<void> {
const email = useAuth().user.value?.email;
await fetchWithApi("/auth/verify-email", { method: "POST", body: { email } });
}
return {
fetchGuilds,
@ -62,10 +83,15 @@ export const useApi = () => {
fetchMember,
fetchUsers,
fetchUser,
fetchFriends,
addFriend,
removeFriend,
fetchMessages,
fetchMessage,
createGuild,
joinGuild,
createChannel
createChannel,
fetchInstanceStats,
sendVerificationEmail
}
}

View file

@ -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) {
@ -37,13 +38,19 @@ export const useAuth = () => {
//await fetchUser();
}
async function logout(password: string) {
console.log("password:", password);
async function logout() {
console.log("access:", accessToken.value);
const hashedPass = await hashPassword(password);
console.log("hashed");
const res = await fetchWithApi("/auth/revoke", {
await fetchWithApi("/auth/logout", { method: "GET", credentials: "include" });
clearAuth();
return await navigateTo("/login");
}
async function revoke(password: string) {
const hashedPass = await hashPassword(password);
await fetchWithApi("/auth/revoke", {
method: "POST",
body:
{
@ -54,10 +61,6 @@ export const useAuth = () => {
clearAuth();
}
async function revoke() {
clearAuth();
}
async function refresh() {
console.log("refreshing");
const res = await fetchWithApi("/auth/refresh", {
@ -75,7 +78,7 @@ export const useAuth = () => {
async function fetchUser() {
if (!accessToken.value) return;
console.log("fetchuser access token:", accessToken.value);
const res = await fetchWithApi("/users/me") as UserResponse;
const res = await fetchWithApi("/me") as UserResponse;
user.value = res;
return user.value;
}
@ -88,8 +91,22 @@ export const useAuth = () => {
return user.value;
}
// as in email the password link
async function resetPassword() {
// ...
}
async function disableAccount() {
// ...
}
async function deleteAccount() {
// ...
}
return {
accessToken,
clearAuth,
register,
login,
logout,