diff --git a/backend/routes/auth/signin.js b/backend/routes/auth/signin.js index aa0057d..454acaa 100644 --- a/backend/routes/auth/signin.js +++ b/backend/routes/auth/signin.js @@ -24,10 +24,10 @@ module.exports = function (sequelize) { if (!passwordMatch) { return res.status(401).json({ error: "Authentication failed" }); } - const token = jwt.sign({ userId: user.id }, "your-secret-key", { + const accessToken = jwt.sign({ userId: user.id }, "your-secret-key", { expiresIn: "1h", }); - res.status(200).json({ token }); + res.status(200).json({ access_token: accessToken, user }); } catch (error) { console.error(error); res.status(500).send("Sign up failed"); diff --git a/backend/routes/auth/signup.js b/backend/routes/auth/signup.js index 20acbf6..7f1106f 100644 --- a/backend/routes/auth/signup.js +++ b/backend/routes/auth/signup.js @@ -32,7 +32,7 @@ module.exports = function (sequelize) { expiresIn: "1h", }); - user.password = undefined;; + user.password = undefined; res.status(200).json({ access_token: accessToken, user }); } catch (error) { console.error(error); diff --git a/frontend/messages/en.json b/frontend/messages/en.json index 35bb441..3dd82a0 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -22,7 +22,11 @@ "title": "Open Source Test Case Management Tool", "description": "Integrate and manage all your software testing", "docs": "Docs", - "projects": "Projects" + "projects": "Projects", + "account": "Account", + "signup": "Sign up", + "signin": "Sign in", + "signout": "Sign out" }, "Auth": { "account": "Account", diff --git a/frontend/messages/ja.json b/frontend/messages/ja.json index fde1998..acf9121 100644 --- a/frontend/messages/ja.json +++ b/frontend/messages/ja.json @@ -22,7 +22,11 @@ "title": "オープンソーステストケース管理ツール", "description": "ソフトウェア開発にかかわるすべてのテストを統合管理", "docs": "ドキュメント", - "projects": "プロジェクト" + "projects": "プロジェクト", + "account": "アカウント", + "signup": "新規登録", + "signin": "サインイン", + "signout": "サインアウト" }, "Auth": { "account": "アカウント", diff --git a/frontend/src/app/[locale]/DropdownAccount.tsx b/frontend/src/app/[locale]/DropdownAccount.tsx index 4939ab6..cd5cb1a 100644 --- a/frontend/src/app/[locale]/DropdownAccount.tsx +++ b/frontend/src/app/[locale]/DropdownAccount.tsx @@ -6,56 +6,103 @@ import { DropdownMenu, DropdownItem, } from "@nextui-org/react"; -import { User, ChevronDown } from "lucide-react"; +import { + User, + ChevronDown, + PenTool, + ArrowRightFromLine, + ArrowRightToLine, +} from "lucide-react"; import { useContext } from "react"; import { TokenContext } from "./TokenProvider"; -import { Link } from "@/src/navigation"; +import { useRouter } from "@/src/navigation"; +import { AccountDropDownMessages } from "@/types/user"; type Props = { + messages: AccountDropDownMessages; locale: string; }; -const signinItems = [ - { uid: "account", title: "Account", href: "/account" }, - { uid: "signout", title: "Sign out", href: "/account/signout" }, -]; - -const signoutItems = [ - { uid: "signin", title: "Sign in", href: "/account/signin" }, -]; - -export default function LangSwitch({ locale }: Props) { +export default function DropdownAccount({ messages, locale }: Props) { + const router = useRouter(); const context = useContext(TokenContext); + + const signOut = () => { + context.setToken(null); + context.removeTokenFromLocalStorage(); + router.push(`/`, { locale: locale }); + }; + + const signinItems = [ + { + uid: "account", + title: messages.account, + icon: , + onPress: () => { + router.push("/account", { locale: locale }); + }, + }, + { + uid: "signout", + title: messages.signOut, + icon: , + onPress: signOut, + }, + ]; + + const signoutItems = [ + { + uid: "signin", + title: messages.signIn, + icon: , + onPress: () => { + router.push("/account/signin", { locale: locale }); + }, + }, + { + uid: "signup", + title: messages.signUp, + icon: , + onPress: () => { + router.push("/account/signup", { locale: locale }); + }, + }, + ]; + return ( - {context.token ? ( + {context.token && context.token.user ? ( {signinItems.map((entry) => ( - - - {entry.title} - - + ))} ) : ( {signoutItems.map((entry) => ( - - - {entry.title} - - + ))} )} diff --git a/frontend/src/app/[locale]/LangSwitch.tsx b/frontend/src/app/[locale]/DropdownLanguage.tsx similarity index 93% rename from frontend/src/app/[locale]/LangSwitch.tsx rename to frontend/src/app/[locale]/DropdownLanguage.tsx index 48a093c..dc20f2d 100644 --- a/frontend/src/app/[locale]/LangSwitch.tsx +++ b/frontend/src/app/[locale]/DropdownLanguage.tsx @@ -15,7 +15,7 @@ const locales = [ { code: "ja", name: "日本語" }, ]; -export default function LangSwitch(params: { locale: string }) { +export default function DropdownLanguage(params: { locale: string }) { const router = useRouter(); const pathname = usePathname(); @@ -36,7 +36,7 @@ export default function LangSwitch(params: { locale: string }) {