fix: redirect to localized dashboard url after login
- Updated login-form.tsx, register-form.tsx, and social-login-button.tsx to utilize useLocale for dynamic callback URL generation based on the user's locale. - Adjusted the default callback URL to include the locale, improving user experience and localization support in authentication flows.
This commit is contained in:
parent
72326403a0
commit
257feba5bd
@ -20,7 +20,7 @@ import { cn } from '@/lib/utils';
|
||||
import { DEFAULT_LOGIN_REDIRECT, Routes } from '@/routes';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { EyeIcon, EyeOffIcon } from 'lucide-react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useTranslations, useLocale } from 'next-intl';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
@ -38,7 +38,9 @@ export const LoginForm = ({ className, callbackUrl: propCallbackUrl }: LoginForm
|
||||
const urlError = searchParams.get('error');
|
||||
const paramCallbackUrl = searchParams.get('callbackUrl');
|
||||
// Use prop callback URL or param callback URL if provided, otherwise use the default login redirect
|
||||
const callbackUrl = propCallbackUrl || paramCallbackUrl || DEFAULT_LOGIN_REDIRECT;
|
||||
const locale = useLocale();
|
||||
const defaultCallbackUrl = `/${locale}${DEFAULT_LOGIN_REDIRECT}`;
|
||||
const callbackUrl = propCallbackUrl || paramCallbackUrl || defaultCallbackUrl;
|
||||
console.log('login form, callbackUrl', callbackUrl);
|
||||
|
||||
const [error, setError] = useState<string | undefined>('');
|
||||
|
@ -18,7 +18,7 @@ import { authClient } from '@/lib/auth-client';
|
||||
import { DEFAULT_LOGIN_REDIRECT, Routes } from '@/routes';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { EyeIcon, EyeOffIcon } from 'lucide-react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useTranslations, useLocale } from 'next-intl';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
@ -34,8 +34,11 @@ export const RegisterForm = ({ callbackUrl: propCallbackUrl }: RegisterFormProps
|
||||
const searchParams = useSearchParams();
|
||||
const paramCallbackUrl = searchParams.get('callbackUrl');
|
||||
// Use prop callback URL or param callback URL if provided, otherwise use the default login redirect
|
||||
const callbackUrl = propCallbackUrl || paramCallbackUrl || DEFAULT_LOGIN_REDIRECT;
|
||||
const locale = useLocale();
|
||||
const defaultCallbackUrl = `/${locale}${DEFAULT_LOGIN_REDIRECT}`;
|
||||
const callbackUrl = propCallbackUrl || paramCallbackUrl || defaultCallbackUrl;
|
||||
console.log('register form, callbackUrl', callbackUrl);
|
||||
|
||||
const [error, setError] = useState<string | undefined>('');
|
||||
const [success, setSuccess] = useState<string | undefined>('');
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
|
@ -8,7 +8,7 @@ import { GitHubIcon } from '@/components/icons/github';
|
||||
import { GoogleIcon } from '@/components/icons/google';
|
||||
import { authClient } from '@/lib/auth-client';
|
||||
import { DEFAULT_LOGIN_REDIRECT, Routes } from '@/routes';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useLocale, useTranslations } from 'next-intl';
|
||||
import { DividerWithText } from '@/components/auth/divider-with-text';
|
||||
|
||||
interface SocialLoginButtonProps {
|
||||
@ -22,7 +22,10 @@ export const SocialLoginButton = ({ callbackUrl: propCallbackUrl }: SocialLoginB
|
||||
const t = useTranslations('AuthPage.login');
|
||||
const searchParams = useSearchParams();
|
||||
const paramCallbackUrl = searchParams.get('callbackUrl');
|
||||
const callbackUrl = propCallbackUrl || paramCallbackUrl || DEFAULT_LOGIN_REDIRECT;
|
||||
// Use prop callback URL or param callback URL if provided, otherwise use the default login redirect
|
||||
const locale = useLocale();
|
||||
const defaultCallbackUrl = `/${locale}${DEFAULT_LOGIN_REDIRECT}`;
|
||||
const callbackUrl = propCallbackUrl || paramCallbackUrl || defaultCallbackUrl;
|
||||
const [isLoading, setIsLoading] = useState<'google' | 'github' | null>(null);
|
||||
console.log('social login button, callbackUrl', callbackUrl);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user