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 12ad794 commit bfbb1a7
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions app/auth/signin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,26 @@ export default function SignIn() {

useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
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.`);
}
}
setError(urlParams.get("error"));
}, []);


const handleSignIn = async (provider: string) => {
setLoading(true);
try {
await signIn(provider, {
callbackUrl: "/dashboard",
});
} catch (error) {
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.");
} catch (err) {
if (err instanceof Error) {
if (err.message.includes("OAuthAccountNotLinked")) {
const providerName = new URLSearchParams(window.location.search).get("provider");
toast.info(`This account is already linked to ${providerName}. Please sign in with that provider.`);
} else {
toast.error("Sign-in failed. Please try again.");
console.error("Sign-in error:", error.message);
console.error("Sign-in error:", err.message);
}
} else {
console.error("An unexpected error occurred:", error);
console.error("An unexpected error occurred:", err);
}
} finally {
setLoading(false);
Expand Down

0 comments on commit bfbb1a7

Please sign in to comment.