Skip to content

Commit 30b82bc

Browse files
Merge pull request #175 from PeerPrep/kevin/new
feat: add notification when same email
2 parents afb44e9 + 64a13d3 commit 30b82bc

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

frontend/src/app/login/page.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,50 @@ import Button from "../components/button/Button";
33
import { FcGoogle } from "@react-icons/all-files/fc/FcGoogle";
44
import { AiFillGithub } from "@react-icons/all-files/ai/AiFillGithub";
55

6-
import { signInWithRedirect } from "firebase/auth";
6+
import { signInWithPopup, signInWithRedirect } from "firebase/auth";
77
import {
88
auth,
99
githubProvider,
1010
googleProvider,
1111
} from "../../libs/firebase-config";
1212
import useRedirectLogin from "../hooks/useRedirectLogin";
13+
import { notification } from "antd";
1314

1415
const roomPage = () => {
16+
const [api, contextHolder] = notification.useNotification();
1517
useRedirectLogin();
18+
19+
const signInError = (err: any) => {
20+
if (err.code === "auth/account-exists-with-different-credential") {
21+
api.error({
22+
message: `Existing Email Exists`,
23+
description:
24+
"You have already signed up with a different provider for that email. Please sign in with the same provider as before.",
25+
placement: "top",
26+
});
27+
}
28+
};
29+
1630
return (
1731
<div className="flex h-full flex-col items-center justify-center">
32+
{contextHolder}
1833
<section className="flex h-[30svh] flex-col items-center justify-center gap-4 rounded-md bg-white px-12 shadow-md">
1934
<h1 className="text-lg font-semibold text-black">Login with</h1>
2035
<div className="flex gap-2">
2136
<Button
2237
className="bg-blue-500 px-4 hover:bg-blue-600 focus:bg-blue-700"
23-
onClick={() => signInWithRedirect(auth, googleProvider)}
38+
onClick={() =>
39+
signInWithPopup(auth, googleProvider).catch(signInError)
40+
}
2441
>
2542
<FcGoogle className="text-xl" />
2643
Google
2744
</Button>
2845
<Button
2946
className="bg-primary px-4"
30-
onClick={() => signInWithRedirect(auth, githubProvider)}
47+
onClick={() =>
48+
signInWithPopup(auth, githubProvider).catch(signInError)
49+
}
3150
>
3251
<AiFillGithub className="text-xl" />
3352
GitHub

0 commit comments

Comments
 (0)