Skip to content

Commit 4b7edbd

Browse files
authored
Fix callback getting appended to the url when signin button is clicked on login page (#1178)
Added guard clause to prevent signin() method from being called on login page as it tries to navigate to login page and causing callback url getting appended in the url bar issue.
1 parent 871253f commit 4b7edbd

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

components/Nav/Nav.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22
import { api } from "@/server/trpc/react";
3+
import { usePathname } from "next/navigation";
34
import {
45
Disclosure,
56
DisclosureButton,
@@ -40,6 +41,8 @@ const Nav = ({
4041
enabled: session ? true : false,
4142
});
4243

44+
const pathname = usePathname();
45+
4346
const userNavigation = [
4447
{
4548
name: "Your Profile",
@@ -55,6 +58,18 @@ const Nav = ({
5558

5659
const hasNotifications = !!count && count > 0;
5760

61+
const handleSignInPageNavigation = () => {
62+
/**
63+
* * NextAuth.js automatically adds current url to the callbackurl prop in the singin() method.
64+
* * As Navbar is always present, spamming SignIn button causes login page url getting appended in the url bar.
65+
*/
66+
if (pathname === "/get-started") {
67+
return;
68+
}
69+
70+
signIn();
71+
};
72+
5873
return (
5974
<Disclosure as="nav" className="bg-neutral-100 dark:bg-black">
6075
{({ close, open }) => (
@@ -117,12 +132,15 @@ const Nav = ({
117132
</>
118133
) : (
119134
<>
120-
<button className="nav-button" onClick={() => signIn()}>
135+
<button
136+
className="nav-button"
137+
onClick={handleSignInPageNavigation}
138+
>
121139
Sign in
122140
</button>
123141
<button
124142
className="primary-button"
125-
onClick={() => signIn()}
143+
onClick={handleSignInPageNavigation}
126144
>
127145
Sign up for free
128146
</button>

0 commit comments

Comments
 (0)