api for fetching user profile
This commit is contained in:
18
client/src/lib/user.ts
Normal file
18
client/src/lib/user.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user