summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/api/user.ts13
-rw-r--r--src/lib/contexts/Auth.context.tsx30
2 files changed, 42 insertions, 1 deletions
diff --git a/src/lib/api/user.ts b/src/lib/api/user.ts
new file mode 100644
index 0000000..86dfce8
--- /dev/null
+++ b/src/lib/api/user.ts
@@ -0,0 +1,13 @@
+const API_URL = process.env.NEXT_PUBLIC_API_URL;
+
+export async function getUserByUsername(username: string) {
+ if (!username) throw new Error('Username is required');
+
+ const res = await fetch(`${API_URL}/api/users/${username}`, {
+ cache: 'no-store',
+ });
+
+ if (!res.ok) throw new Error(`User not found: ${username}`);
+
+ return res.json();
+}
diff --git a/src/lib/contexts/Auth.context.tsx b/src/lib/contexts/Auth.context.tsx
index fbf2e24..4e567ba 100644
--- a/src/lib/contexts/Auth.context.tsx
+++ b/src/lib/contexts/Auth.context.tsx
@@ -4,12 +4,38 @@ import React, { createContext, useState, useContext, useEffect } from 'react';
export type User = {
id: number;
username: string;
+ email: string;
+ password?: string;
avatar?: string;
banner_file?: string;
+ description?: string;
premium?: boolean;
is_banned?: boolean;
is_moderator?: boolean;
+ token_version?: number;
+ profile?: {
+ id: number;
+ user_id: number;
+ avatar_file?: string;
+ banner_file?: string;
+ description?: string;
+ publications_count?: number;
+ collections_count?: number;
+ subscriptions_count?: number;
+ followers_count?: number;
+ following_count?: number;
+ };
+ integrations?: {
+ facebook?: string | null;
+ pinterest?: string | null;
+ discord?: string | null;
+ artstation?: string | null;
+ x?: string | null; // Twitter/X
+ behance?: string | null;
+ instagram?: string | null;
+ };
};
+
interface AuthContextType {
user: User | null;
setUser: (user: User | null) => void;
@@ -33,7 +59,9 @@ export const AuthContextProvider = ({ children }: React.PropsWithChildren) => {
if (!res.ok) return;
const userData = await res.json();
setUser(userData);
- } catch {}
+ } catch (err) {
+ console.error('Error fetching user:', err);
+ }
};
fetchUser();