@@ -4,22 +4,28 @@ import { signIn } from 'next-auth/react';
44import Image from 'next/image' ;
55import Link from 'next/link' ;
66import { useSearchParams } from 'next/navigation' ;
7- import { FormEvent , useState } from 'react' ;
7+ import { FormEvent , Suspense , useEffect , useState } from 'react' ;
88import { toast } from 'react-toastify' ;
99
10- export default function Signin ( ) {
11- const [ email , setEmail ] = useState ( '' ) ;
12- const [ password , setPassword ] = useState ( '' ) ;
10+ function OAuthError ( ) {
1311 const params = useSearchParams ( ) ;
1412
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+ }
2121 }
22- }
22+ } , [ params ] ) ;
23+ return null ;
24+ }
25+
26+ export default function Signin ( ) {
27+ const [ email , setEmail ] = useState ( '' ) ;
28+ const [ password , setPassword ] = useState ( '' ) ;
2329
2430 async function onSignin ( e : FormEvent < HTMLFormElement > ) {
2531 e . preventDefault ( ) ;
@@ -115,6 +121,10 @@ export default function Signin() {
115121 </ form >
116122 </ div >
117123 </ div >
124+ < Suspense >
125+ { /* Suspense is needed because 🤔: https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout */ }
126+ < OAuthError />
127+ </ Suspense >
118128 </ div >
119129 ) ;
120130}
0 commit comments