@@ -3,31 +3,50 @@ import Button from "../components/button/Button";
3
3
import { FcGoogle } from "@react-icons/all-files/fc/FcGoogle" ;
4
4
import { AiFillGithub } from "@react-icons/all-files/ai/AiFillGithub" ;
5
5
6
- import { signInWithRedirect } from "firebase/auth" ;
6
+ import { signInWithPopup , signInWithRedirect } from "firebase/auth" ;
7
7
import {
8
8
auth ,
9
9
githubProvider ,
10
10
googleProvider ,
11
11
} from "../../libs/firebase-config" ;
12
12
import useRedirectLogin from "../hooks/useRedirectLogin" ;
13
+ import { notification } from "antd" ;
13
14
14
15
const roomPage = ( ) => {
16
+ const [ api , contextHolder ] = notification . useNotification ( ) ;
15
17
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
+
16
30
return (
17
31
< div className = "flex h-full flex-col items-center justify-center" >
32
+ { contextHolder }
18
33
< section className = "flex h-[30svh] flex-col items-center justify-center gap-4 rounded-md bg-white px-12 shadow-md" >
19
34
< h1 className = "text-lg font-semibold text-black" > Login with</ h1 >
20
35
< div className = "flex gap-2" >
21
36
< Button
22
37
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
+ }
24
41
>
25
42
< FcGoogle className = "text-xl" />
26
43
Google
27
44
</ Button >
28
45
< Button
29
46
className = "bg-primary px-4"
30
- onClick = { ( ) => signInWithRedirect ( auth , githubProvider ) }
47
+ onClick = { ( ) =>
48
+ signInWithPopup ( auth , githubProvider ) . catch ( signInError )
49
+ }
31
50
>
32
51
< AiFillGithub className = "text-xl" />
33
52
GitHub
0 commit comments