@@ -4,22 +4,28 @@ import { signIn } from 'next-auth/react';
4
4
import Image from 'next/image' ;
5
5
import Link from 'next/link' ;
6
6
import { useSearchParams } from 'next/navigation' ;
7
- import { FormEvent , useState } from 'react' ;
7
+ import { FormEvent , Suspense , useEffect , useState } from 'react' ;
8
8
import { toast } from 'react-toastify' ;
9
9
10
- export default function Signin ( ) {
11
- const [ email , setEmail ] = useState ( '' ) ;
12
- const [ password , setPassword ] = useState ( '' ) ;
10
+ function OAuthError ( ) {
13
11
const params = useSearchParams ( ) ;
14
12
15
- const error = params . get ( 'error' ) ;
16
- if ( error ) {
17
- if ( error === 'OAuthAccountNotLinked' ) {
18
- toast . error ( 'Unable to signin. The user email may be already in use.' ) ;
19
- } else {
20
- toast . error ( `Authentication error: ${ error . toString ( ) } ` ) ;
13
+ useEffect ( ( ) => {
14
+ const error = params . get ( 'error' ) ;
15
+ if ( error ) {
16
+ if ( error === 'OAuthAccountNotLinked' ) {
17
+ toast . error ( 'Unable to signin. The user email may be already in use.' ) ;
18
+ } else {
19
+ toast . error ( `Authentication error: ${ error . toString ( ) } ` ) ;
20
+ }
21
21
}
22
- }
22
+ } , [ params ] ) ;
23
+ return null ;
24
+ }
25
+
26
+ export default function Signin ( ) {
27
+ const [ email , setEmail ] = useState ( '' ) ;
28
+ const [ password , setPassword ] = useState ( '' ) ;
23
29
24
30
async function onSignin ( e : FormEvent < HTMLFormElement > ) {
25
31
e . preventDefault ( ) ;
@@ -115,6 +121,10 @@ export default function Signin() {
115
121
</ form >
116
122
</ div >
117
123
</ div >
124
+ < Suspense >
125
+ { /* Suspense is needed because 🤔: https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout */ }
126
+ < OAuthError />
127
+ </ Suspense >
118
128
</ div >
119
129
) ;
120
130
}
0 commit comments