From d3bceed42caca6ac8c39ebe0c929f7d3c13d2bfa Mon Sep 17 00:00:00 2001 From: l3wdfut4pwr Date: Thu, 9 Apr 2026 15:20:56 +0300 Subject: update settings --- src/app/profile/[username]/page.tsx | 7 +- src/components/settings/AccountButton.tsx | 17 +++++ src/components/settings/SecurityPage.tsx | 111 ++++++++++++++++-------------- src/lib/contexts/Auth.context.tsx | 16 +++-- 4 files changed, 88 insertions(+), 63 deletions(-) create mode 100644 src/components/settings/AccountButton.tsx diff --git a/src/app/profile/[username]/page.tsx b/src/app/profile/[username]/page.tsx index cad11bb..ea13b36 100644 --- a/src/app/profile/[username]/page.tsx +++ b/src/app/profile/[username]/page.tsx @@ -1,11 +1,10 @@ -import Image from 'next/image'; -import { Button } from '@/components/ui'; +import AccountButton from '@/components/settings/AccountButton'; import { getUserByUsername } from '@/lib/api/user'; import { User } from '@/lib/contexts/Auth.context'; + interface ProfilePageProps { params: Promise<{ username: string }>; } - export default async function Profile({ params }: ProfilePageProps) { const { username } = await params; @@ -76,7 +75,7 @@ export default async function Profile({ params }: ProfilePageProps) {
- + ); diff --git a/src/components/settings/AccountButton.tsx b/src/components/settings/AccountButton.tsx new file mode 100644 index 0000000..ecd0eb4 --- /dev/null +++ b/src/components/settings/AccountButton.tsx @@ -0,0 +1,17 @@ +'use client'; + +import Link from 'next/link'; +import { Button } from '@/components/ui'; +import { useUser } from '@/lib/contexts/Auth.context'; + +export default function AccountButton() { + const user = useUser(); + + if (!user) return null; + + return ( + + ); +} diff --git a/src/components/settings/SecurityPage.tsx b/src/components/settings/SecurityPage.tsx index 6d4ab75..2135696 100644 --- a/src/components/settings/SecurityPage.tsx +++ b/src/components/settings/SecurityPage.tsx @@ -1,37 +1,43 @@ import { InputField } from '@/components/ui/inputfield'; import { Button } from '@/components/ui'; import { Separator } from '@/components/ui'; +import { useAuthContext } from '@/lib/contexts/Auth.context'; + export default function SecurityPage() { + const { user } = useAuthContext(); + + if (!user) return; + + const hasGoogle = !!user.google_id; + const hasPassword = !!user.password; + return ( <>
-
-

- ЗАДАТЬ ПАРОЛЬ -

-
- - - + {hasGoogle && ( +
+

+ ЗАДАТЬ ПАРОЛЬ +

+
+ + +
+ +
- -
- + )} +

СМЕНА ПОЧТЫ @@ -52,34 +58,35 @@ export default function SecurityPage() {

-
-

- СМЕНА ПАРОЛЯ -

-
- - - + {hasPassword && ( +
+

+ СМЕНА ПАРОЛЯ +

+
+ + + +
+ +
- -
- - + )}
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); } }; -- cgit v1.3-3-g829e