Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove username #306

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const Main = () => {
const [isReady, setReady] = useState(false)
const [isVersionError, setVersionError] = useState(false)
const [isAuthenticated, setIsAuthenticated] = useState(false)
const [, setUsername] = useLocalStorage<string>('username', 'Keeper')
const [healthCheck] = useLocalStorage<boolean>('health-check', false)

const [beaconNodeVersion, setBeaconVersion] = useState('')
Expand Down Expand Up @@ -77,10 +76,9 @@ const Main = () => {
? formatSemanticVersion(beaconNodeVersion as string)
: undefined

const storeSessionCookie = async (password: string, username: string) => {
const storeSessionCookie = async (password: string) => {
try {
setLoading(true)
setUsername(username)
const { status } = await axios.post('/api/authenticate', { password })

if (status === 200) {
Expand Down
21 changes: 1 addition & 20 deletions src/components/AuthPrompt/AuthPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Typography from '../Typography/Typography'
export interface AuthModalProps extends Omit<AuthFormProps, 'children'> {
isVisible: boolean
isLoading: boolean
isNamePrompt?: boolean
onClose?: () => void
mode: UiMode
}
Expand All @@ -24,7 +23,6 @@ const AuthPrompt: FC<AuthModalProps> = ({
isLoading,
mode,
onClose,
isNamePrompt,
}) => {
const { t } = useTranslation()
const [isReady, setReady] = useState(false)
Expand Down Expand Up @@ -58,23 +56,6 @@ const AuthPrompt: FC<AuthModalProps> = ({
</Typography>
</div>
<div className='space-y-4'>
{isNamePrompt && (
<Controller
name='username'
control={control as any}
render={({ field: { ref: _ref, ...props }, fieldState }) => (
<Input
tooltip={t('authPrompt.tooltip.displayName')}
toolTipId='displayName'
toolTipMode={UiMode.LIGHT}
label={t('authPrompt.label.name')}
uiMode={mode}
error={fieldState.error?.message}
{...props}
/>
)}
/>
)}
<Controller
name='password'
control={control as any}
Expand All @@ -83,7 +64,7 @@ const AuthPrompt: FC<AuthModalProps> = ({
isAutoFocus
tooltip={t('authPrompt.tooltip.sessionPassword')}
toolTipId='sessionPassword'
label={isNamePrompt ? t('authPrompt.label.sessionPassword') : undefined}
label={t('authPrompt.label.sessionPassword')}
autoComplete='new-password'
type='password'
uiMode={mode}
Expand Down
9 changes: 2 additions & 7 deletions src/forms/AuthenticationForm.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { FC, FormEvent, ReactElement, useEffect } from 'react'
import { Control, useForm } from 'react-hook-form'
import useLocalStorage from '../hooks/useLocalStorage'

export interface AuthFormProps {
children: (props: RenderProps) => ReactElement
onSubmit: (token: string, username: string) => void
onSubmit: (token: string) => void
isVisible: boolean
}

export interface AuthForm {
username: string
password: string
}

Expand All @@ -19,11 +17,9 @@ export interface RenderProps {
}

const AuthenticationForm: FC<AuthFormProps> = ({ children, onSubmit, isVisible }) => {
const [username] = useLocalStorage<string>('username', 'Keeper')

const { control, watch, reset } = useForm<AuthForm>({
defaultValues: {
username,
password: '',
},
mode: 'onChange',
Expand All @@ -36,12 +32,11 @@ const AuthenticationForm: FC<AuthFormProps> = ({ children, onSubmit, isVisible }
}, [isVisible, reset])

const password = watch('password')
const name = watch('username')

const submitForm = (e: FormEvent) => {
e.preventDefault()
if (password) {
onSubmit(password, name)
onSubmit(password)
}
}

Expand Down