@@ -21,6 +21,7 @@ import customize from "./images/welcome/customize.svg";
21
21
import fresh from "./images/welcome/fresh.svg" ;
22
22
import prebuild from "./images/welcome/prebuild.svg" ;
23
23
import exclamation from "./images/exclamation.svg" ;
24
+ import { getURLHash } from "./App" ;
24
25
25
26
26
27
function Item ( props : { icon : string , iconSize ?: string , text : string } ) {
@@ -46,17 +47,32 @@ export function hasVisitedMarketingWebsiteBefore() {
46
47
export function Login ( ) {
47
48
const { setUser } = useContext ( UserContext ) ;
48
49
const { setTeams } = useContext ( TeamsContext ) ;
49
- const showWelcome = ! hasLoggedInBefore ( ) && ! hasVisitedMarketingWebsiteBefore ( ) ;
50
+ const urlHash = getURLHash ( ) ;
51
+ let hostFromContext : string | undefined ;
52
+ try {
53
+ hostFromContext = urlHash . length > 0 ? new URL ( urlHash ) . host : undefined ;
54
+ } catch ( error ) {
55
+ // Hash is not a valid URL
56
+ }
50
57
51
- const [ authProviders , setAuthProviders ] = useState < AuthProviderInfo [ ] > ( [ ] ) ;
52
- const [ errorMessage , setErrorMessage ] = useState < string | undefined > ( undefined ) ;
58
+ const [ authProviders , setAuthProviders ] = useState < AuthProviderInfo [ ] > ( [ ] ) ;
59
+ const [ errorMessage , setErrorMessage ] = useState < string | undefined > ( undefined ) ;
60
+ const [ providerFromContext , setProviderFromContext ] = useState < AuthProviderInfo > ( ) ;
61
+ const showWelcome = ! hasLoggedInBefore ( ) && ! hasVisitedMarketingWebsiteBefore ( ) && ! urlHash . startsWith ( "https://" ) ;
53
62
54
63
useEffect ( ( ) => {
55
64
( async ( ) => {
56
65
setAuthProviders ( await getGitpodService ( ) . server . getAuthProviders ( ) ) ;
57
66
} ) ( ) ;
58
67
} , [ ] )
59
68
69
+ useEffect ( ( ) => {
70
+ if ( hostFromContext && authProviders ) {
71
+ const providerFromContext = authProviders . find ( provider => provider . host === hostFromContext ) ;
72
+ setProviderFromContext ( providerFromContext ) ;
73
+ }
74
+ } , [ authProviders ] )
75
+
60
76
const authorizeSuccessful = async ( payload ?: string ) => {
61
77
updateUser ( ) . catch ( console . error ) ;
62
78
// Check for a valid returnTo in payload
@@ -69,7 +85,7 @@ export function Login() {
69
85
70
86
const updateUser = async ( ) => {
71
87
await getGitpodService ( ) . reconnect ( ) ;
72
- const [ user , teams ] = await Promise . all ( [
88
+ const [ user , teams ] = await Promise . all ( [
73
89
getGitpodService ( ) . server . getLoggedInUser ( ) ,
74
90
getGitpodService ( ) . server . getTeams ( ) ,
75
91
] ) ;
@@ -138,19 +154,35 @@ export function Login() {
138
154
< div className = "mx-auto pb-8" >
139
155
< img src = { gitpodIcon } className = "h-16 mx-auto" alt = "Gitpod's logo" />
140
156
</ div >
157
+
141
158
< div className = "mx-auto text-center pb-8 space-y-2" >
142
- < h1 className = "text-3xl" > Log in{ showWelcome ? '' : ' to Gitpod' } </ h1 >
143
- < h2 className = "uppercase text-sm text-gray-400" > ALWAYS READY-TO-CODE</ h2 >
159
+ { providerFromContext
160
+ ? < >
161
+ < h1 className = "text-3xl" > Log in / Sign up</ h1 >
162
+ < h2 className = "text-m text-gray-400" > Open a cloud-based environment for</ h2 >
163
+ < h2 className = "text-m text-gray-400" > { urlHash } </ h2 >
164
+ </ >
165
+ : < >
166
+ < h1 className = "text-3xl" > Log in{ showWelcome ? '' : ' to Gitpod' } </ h1 >
167
+ < h2 className = "uppercase text-sm text-gray-400" > ALWAYS READY-TO-CODE</ h2 >
168
+ </ > }
144
169
</ div >
170
+
171
+
145
172
< div className = "flex flex-col space-y-3 items-center" >
146
- { authProviders . map ( ap => {
147
- return (
148
- < button key = { "button" + ap . host } className = "btn-login flex-none w-56 h-10 p-0 inline-flex" onClick = { ( ) => openLogin ( ap . host ) } >
149
- { iconForAuthProvider ( ap . authProviderType ) }
150
- < span className = "pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis" > Continue with { simplifyProviderName ( ap . host ) } </ span >
173
+ { providerFromContext
174
+ ?
175
+ < button key = { "button" + providerFromContext . host } className = "btn-login flex-none w-56 h-10 p-0 inline-flex" onClick = { ( ) => openLogin ( providerFromContext . host ) } >
176
+ { iconForAuthProvider ( providerFromContext . authProviderType ) }
177
+ < span className = "pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis" > Continue with { simplifyProviderName ( providerFromContext . host ) } </ span >
151
178
</ button >
152
- ) ;
153
- } ) }
179
+ :
180
+ authProviders . map ( ap =>
181
+ < button key = { "button" + ap . host } className = "btn-login flex-none w-56 h-10 p-0 inline-flex" onClick = { ( ) => openLogin ( ap . host ) } >
182
+ { iconForAuthProvider ( ap . authProviderType ) }
183
+ < span className = "pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis" > Continue with { simplifyProviderName ( ap . host ) } </ span >
184
+ </ button > )
185
+ }
154
186
</ div >
155
187
156
188
{ errorMessage && (
0 commit comments