diff --git a/src/auth.ts b/src/auth.ts index 774e61c..f717a38 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -1,16 +1,5 @@ import NextAuth from "next-auth"; -import { JWT } from "next-auth/jwt"; -import Gitea, { GiteaProfile } from "@/lib/providers/gitea"; - -declare module "next-auth" { - interface User extends GiteaProfile {} -} - -declare module "next-auth/jwt" { - interface JWT { - language?: string; - } -} +import Gitea from "@/lib/providers/gitea"; export const { handlers, signIn, signOut, auth } = NextAuth({ providers: [ @@ -23,17 +12,5 @@ export const { handlers, signIn, signOut, auth } = NextAuth({ }), ], secret: process.env.AUTH_SECRET, - callbacks: { - jwt({ token, user }) { - if (user) { - token.language = user.language; - } - return token; - }, - session({ session, token }) { - session.user.language = token.language; - return session; - }, - }, debug: process.env.NODE_ENV === "development", }); diff --git a/src/components/language-switcher.tsx b/src/components/language-switcher.tsx index 9b9cdda..37d7131 100644 --- a/src/components/language-switcher.tsx +++ b/src/components/language-switcher.tsx @@ -1,4 +1,5 @@ -import { auth } from "@/auth"; +"use client"; + import { Select, SelectContent, @@ -6,19 +7,26 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; +import { useLocale } from "next-intl"; +import { Locale } from "@/i18n/config"; +import { setUserLocale } from "@/services/locale"; const languages = [ { value: "en-US", label: "English (United States)", flag: "🇺🇸" }, { value: "zh-CN", label: "ç®€ä½“ä¸æ–‡", flag: "🇨🇳" }, ]; -export default async function LanguageSwitcher() { - const session = await auth(); - const defaultLanguage = session?.user?.language || "en-US"; +export default function LanguageSwitcher() { + const locale = useLocale(); + + function onChange(value: string) { + const locale = value as Locale; + setUserLocale(locale); + } return (