File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,10 @@ function AuthCallback() {
1313 const [ searchParams ] = useSearchParams ( ) ;
1414 const { isAuthenticated, setToken } = useAuth ( ) ;
1515 const [ redirectTo , setRedirectTo ] = useState ( "/" ) ;
16+ const [ errors , setErrors ] = useState ( null ) ;
1617
1718 const code = searchParams . get ( "code" ) ;
1819 const state = searchParams . get ( "state" ) ;
19- const error = searchParams . get ( "error" ) ;
2020
2121 useEffect ( ( ) => {
2222 if ( ! config || ! config . sso . enabled ) return ;
@@ -27,20 +27,26 @@ function AuthCallback() {
2727 if ( ! currentAuthProvider ) return ;
2828
2929 const { token_path } = currentAuthProvider ;
30- fetchUrl ( `${ INFRAHUB_API_SERVER_URL } ${ token_path } ?code=${ code } &state=${ state } ` ) . then (
31- ( result ) => {
30+ fetchUrl ( `${ INFRAHUB_API_SERVER_URL } ${ token_path } ?code=${ code } &state=${ state } ` )
31+ . then ( ( result ) => {
32+ if ( result . errors ) {
33+ throw result ;
34+ }
35+
3236 setRedirectTo ( result . final_url ) ;
3337 setToken ( result ) ;
34- }
35- ) ;
38+ } )
39+ . catch ( ( error ) => {
40+ setErrors ( error . errors ) ;
41+ } ) ;
3642 } , [ config , protocol , provider ] ) ;
3743
3844 if ( ! config || ! config . sso . enabled ) {
3945 return < Navigate to = "/signin" replace /> ;
4046 }
4147
42- if ( error ) {
43- return < Navigate to = "/signin" replace /> ;
48+ if ( errors ) {
49+ return < Navigate to = "/signin" state = { { errors } } replace /> ;
4450 }
4551
4652 if ( isAuthenticated ) {
Original file line number Diff line number Diff line change @@ -23,6 +23,14 @@ function SignInPage() {
2323 < h2 className = "my-8 text-2xl font-semibold text-gray-900" > Sign in to your account</ h2 >
2424
2525 < SignIn />
26+
27+ { location ?. state ?. errors ?. map (
28+ ( error : { extensions : { code : number } ; message : string } , index : number ) => (
29+ < p key = { index } className = "text-red-500 text-sm mt-2" >
30+ ({ error . extensions . code } ) { error . message }
31+ </ p >
32+ )
33+ ) }
2634 </ div >
2735 </ Card >
2836 </ Content >
You can’t perform that action at this time.
0 commit comments