summaryrefslogtreecommitdiff
path: root/src/lib/contexts/Auth.context.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/contexts/Auth.context.tsx')
-rw-r--r--src/lib/contexts/Auth.context.tsx16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/lib/contexts/Auth.context.tsx b/src/lib/contexts/Auth.context.tsx
index 4e567ba..127c942 100644
--- a/src/lib/contexts/Auth.context.tsx
+++ b/src/lib/contexts/Auth.context.tsx
@@ -5,7 +5,8 @@ export type User = {
id: number;
username: string;
email: string;
- password?: string;
+ password: boolean;
+ google_id?: string | null;
avatar?: string;
banner_file?: string;
description?: string;
@@ -49,18 +50,19 @@ export const AuthContextProvider = ({ children }: React.PropsWithChildren) => {
useEffect(() => {
const fetchUser = async () => {
- const hasCookies = document.cookie.includes('access_token');
- if (!hasCookies) return;
-
try {
const res = await fetch(`${API_URL}/api/me`, {
credentials: 'include',
});
- if (!res.ok) return;
- const userData = await res.json();
- setUser(userData);
+ if (!res.ok) {
+ setUser(null);
+ return;
+ }
+ const data = await res.json();
+ setUser(data.authenticated ? data.user : null);
} catch (err) {
console.error('Error fetching user:', err);
+ setUser(null);
}
};