@@ -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,27 @@ 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
+ const URLFromPrefix = urlHash ? new URL ( urlHash ) . host : null ;
52
+ const showWelcome = ! hasLoggedInBefore ( ) && ! hasVisitedMarketingWebsiteBefore ( ) && urlHash . length === 0 ;
50
53
51
54
const [ authProviders , setAuthProviders ] = useState < AuthProviderInfo [ ] > ( [ ] ) ;
52
55
const [ errorMessage , setErrorMessage ] = useState < string | undefined > ( undefined ) ;
56
+ const [ providerFromPrefix , setProviderFromPrefix ] = useState < AuthProviderInfo > ( ) ;
53
57
54
58
useEffect ( ( ) => {
55
59
( async ( ) => {
56
60
setAuthProviders ( await getGitpodService ( ) . server . getAuthProviders ( ) ) ;
57
61
} ) ( ) ;
58
62
} , [ ] )
59
63
64
+ useEffect ( ( ) => {
65
+ if ( URLFromPrefix ) {
66
+ const providerFromPrefix = authProviders . find ( provider => provider . host === URLFromPrefix ) ;
67
+ setProviderFromPrefix ( providerFromPrefix ) ;
68
+ }
69
+ } , [ authProviders ] )
70
+
60
71
const authorizeSuccessful = async ( payload ?: string ) => {
61
72
updateUser ( ) . catch ( console . error ) ;
62
73
// Check for a valid returnTo in payload
@@ -69,7 +80,7 @@ export function Login() {
69
80
70
81
const updateUser = async ( ) => {
71
82
await getGitpodService ( ) . reconnect ( ) ;
72
- const [ user , teams ] = await Promise . all ( [
83
+ const [ user , teams ] = await Promise . all ( [
73
84
getGitpodService ( ) . server . getLoggedInUser ( ) ,
74
85
getGitpodService ( ) . server . getTeams ( ) ,
75
86
] ) ;
@@ -104,6 +115,49 @@ export function Login() {
104
115
}
105
116
}
106
117
118
+ const renderWelcomeText = ( ) => {
119
+ if ( showWelcome ) {
120
+ return (
121
+ < div className = "mx-auto text-center pb-8 space-y-2" >
122
+ < h1 className = "text-3xl" > Log in to Gitpod</ h1 >
123
+ < h2 className = "uppercase text-sm text-gray-400" > ALWAYS READY-TO-CODE</ h2 >
124
+ </ div >
125
+ )
126
+ }
127
+ return (
128
+ < div className = "mx-auto text-center pb-8 space-y-2" >
129
+ < h1 className = "text-3xl" > Log in / Sign up</ h1 >
130
+ < h2 className = "text-m text-gray-400" > Open a cloud-based environment for</ h2 >
131
+ < h2 className = "text-m text-gray-400" > { urlHash } </ h2 >
132
+ </ div >
133
+ )
134
+ }
135
+
136
+ const renderAuthProviders = ( ) => {
137
+ if ( showWelcome ) {
138
+ < div className = "flex flex-col space-y-3 items-center" >
139
+ { authProviders . map ( ap => {
140
+ return (
141
+ < button key = { "button" + ap . host } className = "btn-login flex-none w-56 h-10 p-0 inline-flex" onClick = { ( ) => openLogin ( ap . host ) } >
142
+ { iconForAuthProvider ( ap . authProviderType ) }
143
+ < span className = "pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis" > Continue with { simplifyProviderName ( ap . host ) } </ span >
144
+ </ button >
145
+ ) ;
146
+ } ) }
147
+ </ div >
148
+ }
149
+ if ( ! showWelcome && providerFromPrefix ) {
150
+ return (
151
+ < div className = "flex flex-col space-y-3 items-center" >
152
+ < button key = { "button" + providerFromPrefix . host } className = "btn-login flex-none w-56 h-10 p-0 inline-flex" onClick = { ( ) => openLogin ( providerFromPrefix . host ) } >
153
+ { iconForAuthProvider ( providerFromPrefix . authProviderType ) }
154
+ < span className = "pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis" > Continue with { simplifyProviderName ( providerFromPrefix . host ) } </ span >
155
+ </ button >
156
+ </ div >
157
+ )
158
+ }
159
+ }
160
+
107
161
return ( < div id = "login-container" className = "z-50 flex w-screen h-screen" >
108
162
{ showWelcome ? < div id = "feature-section" className = "flex-grow bg-gray-100 dark:bg-gray-800 w-1/2 hidden lg:block" >
109
163
< div id = "feature-section-column" className = "flex max-w-xl h-full mx-auto pt-6" >
@@ -138,20 +192,10 @@ export function Login() {
138
192
< div className = "mx-auto pb-8" >
139
193
< img src = { gitpodIcon } className = "h-16 mx-auto" alt = "Gitpod's logo" />
140
194
</ div >
141
- < 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 >
144
- </ div >
145
- < 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 >
151
- </ button >
152
- ) ;
153
- } ) }
154
- </ div >
195
+
196
+ { renderWelcomeText ( ) }
197
+
198
+ { renderAuthProviders ( ) }
155
199
156
200
{ errorMessage && (
157
201
< div className = "mt-16 flex space-x-2 py-6 px-6 w-96 justify-between bg-gitpod-kumquat-light rounded-xl" >
@@ -174,5 +218,5 @@ export function Login() {
174
218
</ div >
175
219
176
220
</ div >
177
- </ div > ) ;
221
+ </ div > ) ;
178
222
}
0 commit comments