From 42040c79182fcc5922d55c29b9104af91ecb127d Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Tue, 25 Nov 2025 21:11:41 +0100 Subject: [PATCH] Implement logout functionality for account page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Create LogoutButton client component using signOut from next-auth/react - Update account page to use LogoutButton instead of static link - Convert account page to async server component for proper i18n - Add locale-aware routing for settings link - Add logging-out-message translations (EN/HR) šŸ¤– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/[locale]/account/LogoutButton.tsx | 20 ++++++++++++++++++++ app/[locale]/account/page.tsx | 13 +++++++------ messages/en.json | 3 ++- messages/hr.json | 3 ++- 4 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 app/[locale]/account/LogoutButton.tsx diff --git a/app/[locale]/account/LogoutButton.tsx b/app/[locale]/account/LogoutButton.tsx new file mode 100644 index 0000000..d4bc1b1 --- /dev/null +++ b/app/[locale]/account/LogoutButton.tsx @@ -0,0 +1,20 @@ +"use client"; + +import { FC } from 'react'; +import LogoutIcon from "@mui/icons-material/Logout"; +import { signOut } from 'next-auth/react'; +import { useLocale, useTranslations } from 'next-intl'; +import { Button } from '@/app/ui/button'; + +export const LogoutButton: FC = () => { + const t = useTranslations('account-page'); + const locale = useLocale(); + + const handleLogout = () => { + signOut({ callbackUrl: `/${locale}/login` }); + }; + + return ( + + ) +} \ No newline at end of file diff --git a/app/[locale]/account/page.tsx b/app/[locale]/account/page.tsx index 7d1c37c..d60ace9 100644 --- a/app/[locale]/account/page.tsx +++ b/app/[locale]/account/page.tsx @@ -2,12 +2,13 @@ import { FC } from 'react'; import { Main } from '@/app/ui/Main'; import Link from 'next/link'; import SettingsIcon from "@mui/icons-material/Settings"; -import LogoutIcon from "@mui/icons-material/Logout"; import AccountCircle from "@mui/icons-material/AccountCircle"; -import { useTranslations } from 'next-intl'; +import { getTranslations, getLocale } from 'next-intl/server'; +import { LogoutButton } from './LogoutButton'; -const Page: FC = () => { - const t = useTranslations('account-page'); +const Page: FC = async () => { + const t = await getTranslations('account-page'); + const locale = await getLocale(); return (
@@ -15,8 +16,8 @@ const Page: FC = () => {

{t('title')}

- {t('settings-button')} - {t('logout-button')} + {t('settings-button')} +
diff --git a/messages/en.json b/messages/en.json index 50c0a1c..8402eb8 100644 --- a/messages/en.json +++ b/messages/en.json @@ -5,7 +5,8 @@ "account-page": { "title": "User account", "settings-button": "User Settings", - "logout-button": "Logout" + "logout-button": "Logout", + "logging-out-message": "Logging out..." }, "PageFooter": { "app-description": "Helping you to stay on top of your utility bills", diff --git a/messages/hr.json b/messages/hr.json index cd3a06c..8725686 100644 --- a/messages/hr.json +++ b/messages/hr.json @@ -5,7 +5,8 @@ "account-page": { "title": "Korisnički račun", "settings-button": "Korisničke postavke", - "logout-button": "Odjava" + "logout-button": "Odjava", + "logging-out-message": "Odjavljujem se..." }, "PageFooter": { "app-description": "Preuzmite kontrolu nad svojim režijama!",