admin login fixed.
Build & Push / Pipeline Tests (push) Failing after 1m34s
Build & Push / Build & Push Docker Image (push) Has been skipped
Test / Type Check (all packages) (push) Successful in 56s
Test / API Unit Tests (push) Successful in 1m8s
Test / Homepage Unit Tests (push) Successful in 47s
Test / Carplace Unit Tests (push) Successful in 43s
Test / Admin Unit Tests (push) Successful in 46s
Test / Dashboard Unit Tests (push) Failing after 43s
Test / API Integration Tests (push) Successful in 1m8s
Build & Push / Pipeline Tests (push) Failing after 1m34s
Build & Push / Build & Push Docker Image (push) Has been skipped
Test / Type Check (all packages) (push) Successful in 56s
Test / API Unit Tests (push) Successful in 1m8s
Test / Homepage Unit Tests (push) Successful in 47s
Test / Carplace Unit Tests (push) Successful in 43s
Test / Admin Unit Tests (push) Successful in 46s
Test / Dashboard Unit Tests (push) Failing after 43s
Test / API Integration Tests (push) Successful in 1m8s
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { SignInForm } from '@/components/auth/SignInForm'
|
||||
import { isLocale, isMode, type Locale } from '@/lib/localization/config'
|
||||
import { notFound } from 'next/navigation'
|
||||
import { Suspense } from 'react'
|
||||
|
||||
export default async function AdminSignInPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ locale: string; mode: string }>
|
||||
}) {
|
||||
const { locale: localeValue, mode } = await params
|
||||
if (!isLocale(localeValue)) notFound()
|
||||
if (!isMode(mode)) notFound()
|
||||
|
||||
return (
|
||||
<Suspense fallback={null}>
|
||||
<SignInForm locale={localeValue as Locale} authMode="admin" />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
@@ -45,7 +45,7 @@ const dicts: Record<string, Dict> = {
|
||||
verify: 'Verify code',
|
||||
verifying: 'Verifying…',
|
||||
authCode: 'Authentication code',
|
||||
enterCode: 'Enter the 6-digit code from your authenticator app.',
|
||||
enterCode: 'Enter the 6-digit code sent to your admin email, or use your authenticator app.',
|
||||
totpPlaceholder: '000000 or XXXX-XXXX-XXXX',
|
||||
back: 'Back to credentials',
|
||||
forgotPassword: 'Forgot your password?',
|
||||
@@ -67,7 +67,7 @@ const dicts: Record<string, Dict> = {
|
||||
verify: 'Vérifier le code',
|
||||
verifying: 'Vérification…',
|
||||
authCode: "Code d'authentification",
|
||||
enterCode: "Entrez le code à 6 chiffres de votre application d'authentification.",
|
||||
enterCode: 'Entrez le code à 6 chiffres envoyé à votre e-mail admin, ou utilisez votre application d’authentification.',
|
||||
totpPlaceholder: '000000 ou XXXX-XXXX-XXXX',
|
||||
back: 'Retour aux identifiants',
|
||||
forgotPassword: 'Mot de passe oublié ?',
|
||||
@@ -89,7 +89,7 @@ const dicts: Record<string, Dict> = {
|
||||
verify: 'تحقق من الرمز',
|
||||
verifying: 'جارٍ التحقق…',
|
||||
authCode: 'رمز المصادقة',
|
||||
enterCode: 'أدخل الرمز المكون من 6 أرقام من تطبيق المصادقة.',
|
||||
enterCode: 'أدخل الرمز المكون من 6 أرقام المرسل إلى بريد المسؤول، أو استخدم تطبيق المصادقة.',
|
||||
totpPlaceholder: '000000 أو XXXX-XXXX-XXXX',
|
||||
back: 'العودة إلى بيانات الدخول',
|
||||
forgotPassword: 'نسيت كلمة المرور؟',
|
||||
@@ -101,10 +101,28 @@ const dicts: Record<string, Dict> = {
|
||||
},
|
||||
};
|
||||
|
||||
export function SignInForm({ locale }: { locale: Locale }) {
|
||||
function isAdminDestination(value: string) {
|
||||
if (!value) return false;
|
||||
|
||||
try {
|
||||
const url = new URL(value, typeof window === 'undefined' ? 'http://localhost' : window.location.origin);
|
||||
return url.pathname.startsWith('/admin');
|
||||
} catch {
|
||||
return value.startsWith('/admin');
|
||||
}
|
||||
}
|
||||
|
||||
export function SignInForm({
|
||||
locale,
|
||||
authMode = 'auto',
|
||||
}: {
|
||||
locale: Locale;
|
||||
authMode?: 'auto' | 'admin' | 'employee';
|
||||
}) {
|
||||
const dict = (dicts[locale] ?? dicts.en) as Dict;
|
||||
const searchParams = useSearchParams();
|
||||
const mode = modeFromPathname(usePathname());
|
||||
const pathname = usePathname();
|
||||
const mode = modeFromPathname(pathname);
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
@@ -113,8 +131,12 @@ export function SignInForm({ locale }: { locale: Locale }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const requestedPortal = searchParams.get('portal');
|
||||
const requestedNext = searchParams.get('next') || searchParams.get('redirect') || '';
|
||||
const employeeRedirect = searchParams.get('redirect') || '/dashboard';
|
||||
const preferAdminAuth = requestedPortal === 'admin';
|
||||
const preferAdminAuth =
|
||||
authMode === 'admin' ||
|
||||
pathname.includes('/admin-sign-in') ||
|
||||
(authMode === 'auto' && (requestedPortal === 'admin' || isAdminDestination(requestedNext)));
|
||||
|
||||
async function handleCredentials(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
@@ -196,6 +218,7 @@ export function SignInForm({ locale }: { locale: Locale }) {
|
||||
}
|
||||
|
||||
if (await tryEmployeeLogin()) return;
|
||||
if (await tryAdminLogin()) return;
|
||||
|
||||
setError(dict.invalidCredentials);
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user