Skip to content

Commit

Permalink
Update page.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
ArhanAnsari authored Nov 4, 2024
1 parent 19a8a5f commit 12ad794
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions app/auth/signin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ export default function SignIn() {
const { data: session } = useSession();
const [loading, setLoading] = useState(false);
const [showFallbackLink, setShowFallbackLink] = useState(false);
const [error, setError] = useState<string | null>(null); // Add error state
const [error, setError] = useState<string | null>(null);

useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
setError(urlParams.get("error")); // Get error from URL
const potentialError = urlParams.get("error");
if (potentialError) {
setError(potentialError);
if (potentialError === "OAuthAccountNotLinked") {
const provider = urlParams.get("provider");
toast.info(`This account is already linked to ${provider}. Please sign in with that provider.`);
}
}
}, []);


const handleSignIn = async (provider: string) => {
setLoading(true);
try {
await signIn(provider, {
callbackUrl: "/dashboard",
});
} catch (error) {
{error === "OAuthAccountNotLinked" && (
<p className="text-red-500 mt-2">
This account is already linked to{" "}
{/* Extract correct provider from URL */}
{new URLSearchParams(window.location.search).get("provider")}. Please sign in
with that provider.
</p>
)}
if (error instanceof Error) {
if (error.message.includes("OAuthAccountNotLinked")) {
toast.info("This account is not linked. Please sign up first or sign in using the originally linked provider.");
Expand Down

0 comments on commit 12ad794

Please sign in to comment.