@@ -2,19 +2,19 @@ import Box from "@material-ui/core/Box"
2
2
import Button from "@material-ui/core/Button"
3
3
import Link from "@material-ui/core/Link"
4
4
import { makeStyles } from "@material-ui/core/styles"
5
+ import Typography from "@material-ui/core/Typography"
5
6
import TextField from "@material-ui/core/TextField"
6
7
import GitHubIcon from "@material-ui/icons/GitHub"
7
8
import KeyIcon from "@material-ui/icons/VpnKey"
8
9
import { Stack } from "components/Stack/Stack"
9
10
import { FormikContextType , FormikTouched , useFormik } from "formik"
10
- import { FC } from "react"
11
+ import { FC , useState } from "react"
11
12
import * as Yup from "yup"
12
13
import { AuthMethods } from "../../api/typesGenerated"
13
14
import { getFormHelpers , onChangeTrimmed } from "../../util/formUtils"
14
15
import { LoadingButton } from "./../LoadingButton/LoadingButton"
15
16
import { AlertBanner } from "components/AlertBanner/AlertBanner"
16
17
import { useTranslation } from "react-i18next"
17
- import { useSearchParams } from "react-router-dom"
18
18
19
19
/**
20
20
* BuiltInAuthFormValues describes a form using built-in (email/password)
@@ -95,6 +95,12 @@ const useStyles = makeStyles((theme) => ({
95
95
fontSize : 12 ,
96
96
letterSpacing : 1 ,
97
97
} ,
98
+ showPasswordLink : {
99
+ cursor : "pointer" ,
100
+ fontSize : 12 ,
101
+ color : theme . palette . text . secondary ,
102
+ marginTop : 12 ,
103
+ }
98
104
} ) )
99
105
100
106
export interface SignInFormProps {
@@ -115,8 +121,10 @@ export const SignInForm: FC<React.PropsWithChildren<SignInFormProps>> = ({
115
121
onSubmit,
116
122
initialTouched,
117
123
} ) => {
124
+ const nonPasswordAuthEnabled = authMethods ?. github . enabled || authMethods ?. oidc . enabled
125
+
126
+ const [ showPasswordAuth , setShowPasswordAuth ] = useState ( ! nonPasswordAuthEnabled ) ;
118
127
const styles = useStyles ( )
119
- const [ searchParams ] = useSearchParams ( )
120
128
const form : FormikContextType < BuiltInAuthFormValues > =
121
129
useFormik < BuiltInAuthFormValues > ( {
122
130
initialValues : {
@@ -139,17 +147,13 @@ export const SignInForm: FC<React.PropsWithChildren<SignInFormProps>> = ({
139
147
const commonTranslation = useTranslation ( "common" )
140
148
const loginPageTranslation = useTranslation ( "loginPage" )
141
149
142
- const passwordHidden = authMethods ?. password . hidden
143
- const urlParamOverride = searchParams . get ( "auth" ) === "password"
144
- const showPasswordLogin = ! passwordHidden || urlParamOverride
145
-
146
150
return (
147
151
< div className = { styles . root } >
148
152
< h1 className = { styles . title } >
149
153
{ loginPageTranslation . t ( "signInTo" ) } { " " }
150
154
< strong > { commonTranslation . t ( "coder" ) } </ strong >
151
155
</ h1 >
152
- { showPasswordLogin && (
156
+ { showPasswordAuth && (
153
157
< form onSubmit = { form . handleSubmit } >
154
158
< Stack >
155
159
{ Object . keys ( loginErrors ) . map (
@@ -195,15 +199,15 @@ export const SignInForm: FC<React.PropsWithChildren<SignInFormProps>> = ({
195
199
</ Stack >
196
200
</ form >
197
201
) }
198
- { showPasswordLogin &&
199
- ( authMethods ?. github . enabled || authMethods ?. oidc . enabled ) && (
202
+ { showPasswordAuth &&
203
+ ( nonPasswordAuthEnabled ) && (
200
204
< div className = { styles . divider } >
201
205
< div className = { styles . dividerLine } />
202
206
< div className = { styles . dividerLabel } > Or</ div >
203
207
< div className = { styles . dividerLine } />
204
208
</ div >
205
209
) }
206
- { ( authMethods ?. github . enabled || authMethods ?. oidc . enabled ) && (
210
+ { ( nonPasswordAuthEnabled ) && (
207
211
< Box display = "grid" gridGap = "16px" >
208
212
{ authMethods . github . enabled && (
209
213
< Link
@@ -255,6 +259,11 @@ export const SignInForm: FC<React.PropsWithChildren<SignInFormProps>> = ({
255
259
) }
256
260
</ Box >
257
261
) }
262
+ { ! showPasswordAuth &&
263
+ < Typography className = { styles . showPasswordLink } onClick = { ( ) => setShowPasswordAuth ( true ) } >
264
+ Show password login
265
+ </ Typography >
266
+ }
258
267
</ div >
259
268
)
260
269
}
0 commit comments