6
6
7
7
import { useMutation } from "@tanstack/react-query" ;
8
8
import { FC , useCallback , useState } from "react" ;
9
+ import Alert from "../components/Alert" ;
9
10
import { Button } from "../components/Button" ;
10
11
import { TextInputField } from "../components/forms/TextInputField" ;
12
+ import { getGitpodService } from "../service/service" ;
11
13
12
14
export const SSOLoginForm : FC = ( ) => {
13
15
const [ orgSlug , setOrgSlug ] = useState ( "" ) ;
16
+ const [ error , setError ] = useState ( "" ) ;
17
+
14
18
// TODO: remove this
15
19
const [ loginUrl , setLoginUrl ] = useState ( "" ) ;
16
20
@@ -20,6 +24,7 @@ export const SSOLoginForm: FC = () => {
20
24
// return provider id
21
25
await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
22
26
27
+ // return await getGitpodService().server.getSSOLoginID(slug);
23
28
return { id : "sample-id" } ;
24
29
} ,
25
30
} ) ;
@@ -29,10 +34,16 @@ export const SSOLoginForm: FC = () => {
29
34
e . preventDefault ( ) ;
30
35
31
36
// make api call to get provider id by slug
32
- const { id } = await exchangeSlug . mutateAsync ( { slug : orgSlug } ) ;
37
+ const resp = await exchangeSlug . mutateAsync ( { slug : orgSlug } ) ;
38
+ const loginId = resp ?. id ;
39
+
40
+ // No SSO configured for provided slug
41
+ if ( ! loginId ) {
42
+ setError ( "It looks like SSO has not been configured for that organization." ) ;
43
+ }
33
44
34
45
// create sso login url with provider id
35
- const loginUrl = `/oidc/start/?id=${ id } ` ;
46
+ const loginUrl = `/oidc/start/?id=${ loginId } ` ;
36
47
setLoginUrl ( loginUrl ) ;
37
48
38
49
// openAuthorize window for sso w/ login url
@@ -49,6 +60,7 @@ export const SSOLoginForm: FC = () => {
49
60
Continue with SSO
50
61
</ Button >
51
62
{ loginUrl && < p > { loginUrl } </ p > }
63
+ { error && < Alert type = "info" > { error } </ Alert > }
52
64
</ div >
53
65
</ form >
54
66
) ;
0 commit comments