refactor(auth): apply fixed public instance locale resolution to auth pages
This commit is contained in:
@@ -1,9 +1,6 @@
|
|||||||
import { AuthPageShell } from "@/components/auth/auth-page-shell";
|
import { AuthPageShell } from "@/components/auth/auth-page-shell";
|
||||||
import { LocaleSelectForm } from "@/components/i18n/locale-select-form";
|
|
||||||
import { getPublicBranding } from "@/server/branding/runtime";
|
import { getPublicBranding } from "@/server/branding/runtime";
|
||||||
import { getSqliteConnection } from "@/server/db/client";
|
import { resolvePublicLocale } from "@/server/i18n/resolver";
|
||||||
import { ContentTranslationService } from "@/server/i18n/content";
|
|
||||||
import { resolveRequestLocale } from "@/server/i18n/resolver";
|
|
||||||
import { createTranslator } from "@/server/i18n/translator";
|
import { createTranslator } from "@/server/i18n/translator";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Alert, AlertDescription } from "poyraz-ui/molecules";
|
import { Alert, AlertDescription } from "poyraz-ui/molecules";
|
||||||
@@ -12,9 +9,8 @@ export const dynamic = "force-dynamic";
|
|||||||
|
|
||||||
export default async function ForgotPasswordPage() {
|
export default async function ForgotPasswordPage() {
|
||||||
const branding = getPublicBranding();
|
const branding = getPublicBranding();
|
||||||
const locale = await resolveRequestLocale();
|
const locale = await resolvePublicLocale();
|
||||||
const t = createTranslator(locale.locale, ["auth"]).t;
|
const t = createTranslator(locale.locale, ["auth"]).t;
|
||||||
const localization = new ContentTranslationService(getSqliteConnection().db).getPublicLocalizationContext();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthPageShell
|
<AuthPageShell
|
||||||
@@ -41,7 +37,6 @@ export default async function ForgotPasswordPage() {
|
|||||||
}}
|
}}
|
||||||
form={
|
form={
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<LocaleSelectForm label={t("auth.language")} value={locale.locale} locales={localization.locales} />
|
|
||||||
<Alert variant="info" appearance="soft">
|
<Alert variant="info" appearance="soft">
|
||||||
<AlertDescription>{t("auth.forgot.helper")}</AlertDescription>
|
<AlertDescription>{t("auth.forgot.helper")}</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
import { cookies } from "next/headers";
|
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import {
|
import {
|
||||||
acceptPortalInvitation,
|
acceptPortalInvitation,
|
||||||
getPortalInvitationPreview,
|
|
||||||
PortalInvitationError,
|
PortalInvitationError,
|
||||||
} from "@/server/auth/invitations";
|
} from "@/server/auth/invitations";
|
||||||
import { buildLocaleCookie } from "@/server/i18n/locale";
|
|
||||||
|
|
||||||
function inviteErrorCode(error: unknown): string {
|
function inviteErrorCode(error: unknown): string {
|
||||||
if (!(error instanceof PortalInvitationError)) return "auth.messages.portalInviteFailed";
|
if (!(error instanceof PortalInvitationError)) return "auth.messages.portalInviteFailed";
|
||||||
@@ -27,7 +24,5 @@ export async function acceptInvitation(formData: FormData) {
|
|||||||
redirect(`/invite/${encodeURIComponent(token)}?error=true&code=${inviteErrorCode(error)}`);
|
redirect(`/invite/${encodeURIComponent(token)}?error=true&code=${inviteErrorCode(error)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const locale = getPortalInvitationPreview(token)?.locale ?? "tr";
|
|
||||||
(await cookies()).set(buildLocaleCookie(locale));
|
|
||||||
redirect("/login?code=auth.invite.success");
|
redirect("/login?code=auth.invite.success");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { Input, Label } from "poyraz-ui/atoms";
|
|||||||
import { Alert, AlertDescription } from "poyraz-ui/molecules";
|
import { Alert, AlertDescription } from "poyraz-ui/molecules";
|
||||||
import { getPortalInvitationPreview } from "@/server/auth/invitations";
|
import { getPortalInvitationPreview } from "@/server/auth/invitations";
|
||||||
import { getPublicBranding } from "@/server/branding/runtime";
|
import { getPublicBranding } from "@/server/branding/runtime";
|
||||||
|
import { resolveInvitationLocale } from "@/server/i18n/resolver";
|
||||||
import { createTranslator } from "@/server/i18n/translator";
|
import { createTranslator } from "@/server/i18n/translator";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
@@ -28,7 +29,8 @@ export default async function InvitationPage({
|
|||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const t = createTranslator(invitation.locale, ["auth"]).t;
|
const resolvedLocale = await resolveInvitationLocale(invitation.locale);
|
||||||
|
const t = createTranslator(resolvedLocale.locale, ["auth"]).t;
|
||||||
const query = await searchParams;
|
const query = await searchParams;
|
||||||
const queryCode = query.code ?? null;
|
const queryCode = query.code ?? null;
|
||||||
const queryMessage = queryCode ? t(queryCode) : query.message;
|
const queryMessage = queryCode ? t(queryCode) : query.message;
|
||||||
|
|||||||
+2
-7
@@ -1,16 +1,13 @@
|
|||||||
import { login } from "@/app/login/actions";
|
import { login } from "@/app/login/actions";
|
||||||
import { AuthPageShell } from "@/components/auth/auth-page-shell";
|
import { AuthPageShell } from "@/components/auth/auth-page-shell";
|
||||||
import { ErrorToaster } from "@/components/error-toaster";
|
import { ErrorToaster } from "@/components/error-toaster";
|
||||||
import { LocaleSelectForm } from "@/components/i18n/locale-select-form";
|
|
||||||
import { LockKeyhole, LogIn, Mail } from "lucide-react";
|
import { LockKeyhole, LogIn, Mail } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Input, Label } from "poyraz-ui/atoms";
|
import { Input, Label } from "poyraz-ui/atoms";
|
||||||
import { Alert, AlertDescription } from "poyraz-ui/molecules";
|
import { Alert, AlertDescription } from "poyraz-ui/molecules";
|
||||||
import { SubmitButton } from "@/components/auth/submit-button";
|
import { SubmitButton } from "@/components/auth/submit-button";
|
||||||
import { getPublicBranding } from "@/server/branding/runtime";
|
import { getPublicBranding } from "@/server/branding/runtime";
|
||||||
import { getSqliteConnection } from "@/server/db/client";
|
import { resolvePublicLocale } from "@/server/i18n/resolver";
|
||||||
import { ContentTranslationService } from "@/server/i18n/content";
|
|
||||||
import { resolveRequestLocale } from "@/server/i18n/resolver";
|
|
||||||
import { createTranslator } from "@/server/i18n/translator";
|
import { createTranslator } from "@/server/i18n/translator";
|
||||||
import type { TranslationValues } from "@/lib/i18n";
|
import type { TranslationValues } from "@/lib/i18n";
|
||||||
|
|
||||||
@@ -40,9 +37,8 @@ export default async function LoginPage({
|
|||||||
const code = firstParam(resolvedParams?.code);
|
const code = firstParam(resolvedParams?.code);
|
||||||
const rawMessage = firstParam(resolvedParams?.message);
|
const rawMessage = firstParam(resolvedParams?.message);
|
||||||
const branding = getPublicBranding();
|
const branding = getPublicBranding();
|
||||||
const locale = await resolveRequestLocale();
|
const locale = await resolvePublicLocale();
|
||||||
const t = createTranslator(locale.locale, ["auth"]).t;
|
const t = createTranslator(locale.locale, ["auth"]).t;
|
||||||
const localization = new ContentTranslationService(getSqliteConnection().db).getPublicLocalizationContext();
|
|
||||||
const message = resolveAuthMessage(code, rawMessage, t);
|
const message = resolveAuthMessage(code, rawMessage, t);
|
||||||
const marketing = {
|
const marketing = {
|
||||||
headline: t("auth.marketing.headline"),
|
headline: t("auth.marketing.headline"),
|
||||||
@@ -78,7 +74,6 @@ export default async function LoginPage({
|
|||||||
<AlertDescription>{message}</AlertDescription>
|
<AlertDescription>{message}</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
) : null}
|
) : null}
|
||||||
<LocaleSelectForm label={t("auth.language")} value={locale.locale} locales={localization.locales} />
|
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="email" className="flex items-center gap-2">
|
<Label htmlFor="email" className="flex items-center gap-2">
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { signup } from "@/app/login/actions";
|
import { signup } from "@/app/login/actions";
|
||||||
import { AuthPageShell } from "@/components/auth/auth-page-shell";
|
import { AuthPageShell } from "@/components/auth/auth-page-shell";
|
||||||
import { ErrorToaster } from "@/components/error-toaster";
|
import { ErrorToaster } from "@/components/error-toaster";
|
||||||
import { LocaleSelectForm } from "@/components/i18n/locale-select-form";
|
|
||||||
import { getFirstFreelancerSetupState } from "@/server/auth/setup";
|
import { getFirstFreelancerSetupState } from "@/server/auth/setup";
|
||||||
import { LockKeyhole, Mail, UserPlus } from "lucide-react";
|
import { LockKeyhole, Mail, UserPlus } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -9,9 +8,7 @@ import { redirect } from "next/navigation";
|
|||||||
import { Input, Label } from "poyraz-ui/atoms";
|
import { Input, Label } from "poyraz-ui/atoms";
|
||||||
import { SubmitButton } from "@/components/auth/submit-button";
|
import { SubmitButton } from "@/components/auth/submit-button";
|
||||||
import { getPublicBranding } from "@/server/branding/runtime";
|
import { getPublicBranding } from "@/server/branding/runtime";
|
||||||
import { getSqliteConnection } from "@/server/db/client";
|
import { resolvePublicLocale } from "@/server/i18n/resolver";
|
||||||
import { ContentTranslationService } from "@/server/i18n/content";
|
|
||||||
import { resolveRequestLocale } from "@/server/i18n/resolver";
|
|
||||||
import { createTranslator } from "@/server/i18n/translator";
|
import { createTranslator } from "@/server/i18n/translator";
|
||||||
import type { TranslationValues } from "@/lib/i18n";
|
import type { TranslationValues } from "@/lib/i18n";
|
||||||
|
|
||||||
@@ -53,9 +50,8 @@ export default async function RegisterPage({
|
|||||||
const code = firstParam(resolvedParams?.code);
|
const code = firstParam(resolvedParams?.code);
|
||||||
const rawMessage = firstParam(resolvedParams?.message);
|
const rawMessage = firstParam(resolvedParams?.message);
|
||||||
const branding = getPublicBranding();
|
const branding = getPublicBranding();
|
||||||
const locale = await resolveRequestLocale();
|
const locale = await resolvePublicLocale();
|
||||||
const t = createTranslator(locale.locale, ["auth"]).t;
|
const t = createTranslator(locale.locale, ["auth"]).t;
|
||||||
const localization = new ContentTranslationService(getSqliteConnection().db).getPublicLocalizationContext();
|
|
||||||
const message = resolveAuthMessage(code, rawMessage, t);
|
const message = resolveAuthMessage(code, rawMessage, t);
|
||||||
const marketing = {
|
const marketing = {
|
||||||
headline: t("auth.marketing.headline"),
|
headline: t("auth.marketing.headline"),
|
||||||
@@ -86,7 +82,6 @@ export default async function RegisterPage({
|
|||||||
marketing={marketing}
|
marketing={marketing}
|
||||||
form={
|
form={
|
||||||
<form className="space-y-6">
|
<form className="space-y-6">
|
||||||
<LocaleSelectForm label={t("auth.language")} value={locale.locale} locales={localization.locales} />
|
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="email" className="flex items-center gap-2">
|
<Label htmlFor="email" className="flex items-center gap-2">
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { AuthPageShell } from "@/components/auth/auth-page-shell";
|
import { AuthPageShell } from "@/components/auth/auth-page-shell";
|
||||||
import { LocaleSelectForm } from "@/components/i18n/locale-select-form";
|
|
||||||
import { getPublicBranding } from "@/server/branding/runtime";
|
import { getPublicBranding } from "@/server/branding/runtime";
|
||||||
import { getSqliteConnection } from "@/server/db/client";
|
import { resolvePublicLocale } from "@/server/i18n/resolver";
|
||||||
import { ContentTranslationService } from "@/server/i18n/content";
|
|
||||||
import { resolveRequestLocale } from "@/server/i18n/resolver";
|
|
||||||
import { createTranslator } from "@/server/i18n/translator";
|
import { createTranslator } from "@/server/i18n/translator";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Alert, AlertDescription } from "poyraz-ui/molecules";
|
import { Alert, AlertDescription } from "poyraz-ui/molecules";
|
||||||
@@ -12,9 +9,8 @@ export const dynamic = "force-dynamic";
|
|||||||
|
|
||||||
export default async function ResetPasswordPage() {
|
export default async function ResetPasswordPage() {
|
||||||
const branding = getPublicBranding();
|
const branding = getPublicBranding();
|
||||||
const locale = await resolveRequestLocale();
|
const locale = await resolvePublicLocale();
|
||||||
const t = createTranslator(locale.locale, ["auth"]).t;
|
const t = createTranslator(locale.locale, ["auth"]).t;
|
||||||
const localization = new ContentTranslationService(getSqliteConnection().db).getPublicLocalizationContext();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthPageShell
|
<AuthPageShell
|
||||||
@@ -41,7 +37,6 @@ export default async function ResetPasswordPage() {
|
|||||||
}}
|
}}
|
||||||
form={
|
form={
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<LocaleSelectForm label={t("auth.language")} value={locale.locale} locales={localization.locales} />
|
|
||||||
<Alert variant="info" appearance="soft">
|
<Alert variant="info" appearance="soft">
|
||||||
<AlertDescription>{t("auth.reset.description")}</AlertDescription>
|
<AlertDescription>{t("auth.reset.description")}</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|||||||
Reference in New Issue
Block a user