Skip to content

Commit 28f67b3

Browse files
authored
Merge pull request #64 from LaythAlqadhi/fix/fix-multiple-redirects
fix: fix multiple redirects after signing in
2 parents cf041bf + 268f478 commit 28f67b3

4 files changed

Lines changed: 11 additions & 3 deletions

File tree

full-kit/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ NEXTAUTH_URL=http://localhost:3000
77
NEXTAUTH_SECRET=your_nextauth_secret_here
88

99
HOME_PATHNAME=/dashboards/analytics
10+
NEXT_PUBLIC_HOME_PATHNAME=/dashboards/analytics

full-kit/src/components/auth/sign-in-form.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export function SignInForm() {
3434
const searchParams = useSearchParams()
3535
const router = useRouter()
3636

37-
const redirectPathname = searchParams.get("redirectTo")
37+
const redirectPathname =
38+
searchParams.get("redirectTo") ||
39+
process.env.NEXT_PUBLIC_HOME_PATHNAME ||
40+
"/"
3841

3942
const form = useForm<SignInFormType>({
4043
resolver: zodResolver(SignInSchema),
@@ -62,7 +65,7 @@ export function SignInForm() {
6265
throw new Error(result.error)
6366
}
6467

65-
router.push(redirectPathname || "/")
68+
router.push(redirectPathname)
6669
} catch (error) {
6770
toast({
6871
variant: "destructive",

full-kit/src/components/auth/verify-email-form.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ export function VerifyEmailForm() {
5959
<Form {...form}>
6060
<form onSubmit={form.handleSubmit(onSubmit)} className="grid gap-2">
6161
<Link
62-
href={ensureLocalizedPathname("/", locale)}
62+
href={ensureLocalizedPathname(
63+
process.env.NEXT_PUBLIC_HOME_PATHNAME || "/",
64+
locale
65+
)}
6366
className={cn(buttonVariants({ variant: "default" }))}
6467
>
6568
Skip for now

full-kit/src/middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function redirect(pathname: string, request: NextRequest) {
3333

3434
export async function middleware(request: NextRequest) {
3535
const { pathname } = request.nextUrl
36+
console.log(pathname)
3637
const locale = getLocaleFromPathname(pathname)
3738
const pathnameWithoutLocale = ensureWithoutPrefix(pathname, `/${locale}`)
3839
const isNotPublic = !isPublicRoute(pathnameWithoutLocale)

0 commit comments

Comments
 (0)