api for fetching user profile

This commit is contained in:
Nathaniel Tampus
2023-04-05 22:29:54 +08:00
parent bec764dcee
commit bdc8dab1ad
4 changed files with 61 additions and 0 deletions

18
client/src/lib/user.ts Normal file
View File

@@ -0,0 +1,18 @@
import { API_URL } from "@/config";
import type { User, Game } from "@chessu/types";
export const getProfileData = async (name: string) => {
try {
// TODO: handle caching more efficiently?
const res = await fetch(`${API_URL}/v1/users/${name}`, {
next: { revalidate: 10 }
});
if (res && res.status === 200) {
const data: User & { recentGames: Game[] } = await res.json();
return data;
}
} catch (err) {
console.error(err);
}
};