@@ -21,6 +21,7 @@ import {
2121 useErrorNotification ,
2222} from '@/hooks/useGlobalNotification'
2323import { useTranslation } from 'react-i18next'
24+ import GloTooltip from '@/components/common/GlobalTooltip'
2425/**
2526 * Props interface for the Authenticator component.
2627 */
@@ -32,14 +33,13 @@ interface AuthenticatorProps {
3233}
3334
3435/*
35- Authenticator Component
36-
37- A React component that provides user authentication with email and password input, including
38- registration, verification code flow, and login.
39-
40- @param onAuthSuccess Type: () => void. Callback invoked on successful authentication.
41-
42- @returns JSX.Element The authenticator UI.
36+ Authenticator component.
37+
38+ Provides user authentication UI and flow including login, registration, and email verification code.
39+
40+ @param onAuthSuccess Function. Callback invoked after a successful authentication flow. No default.
41+
42+ @returns JSX.Element The rendered authenticator UI.
4343*/
4444export default function Authenticator ( { onAuthSuccess } : AuthenticatorProps ) {
4545 const [ email , setEmail ] = useState ( '' )
@@ -56,7 +56,18 @@ export default function Authenticator({ onAuthSuccess }: AuthenticatorProps) {
5656 const { showErrorNotification } = useErrorNotification ( )
5757 const [ codeErrorMessage , setCodeErrorMessage ] = useState ( '' )
5858 const { t, i18n } = useTranslation ( )
59-
59+ const [ needCoolDown , setNeedCoolDown ] = useState ( false )
60+ /*
61+ Get current geolocation with a timeout guard.
62+
63+ Resolves with latitude and longitude if available, otherwise rejects on timeout or geolocation error.
64+
65+ @param options PositionOptions. Options passed to navigator.geolocation.getCurrentPosition. Default timeout is 5000 ms if not provided.
66+
67+ @returns Promise<{ latitude: number; longitude: number }> The resolved location coordinates.
68+
69+ @throws {Error } When the location request times out or geolocation reports an error.
70+ */
6071 const getCurrentPositionAsync = ( options : PositionOptions ) => {
6172 return new Promise ( ( resolve , reject ) => {
6273 let resolved = false
@@ -88,12 +99,12 @@ export default function Authenticator({ onAuthSuccess }: AuthenticatorProps) {
8899 } )
89100 }
90101 /*
91- Verify user credentials and handle registration or login.
92-
93- @param email Type: string. The user's email address.
94- @param password Type: string. The user's password.
95-
96- @returns Promise<void> Resolves when the flow completes .
102+ Verify user credentials and handle registration or login based on the active tab .
103+
104+ @param email string. The user's email address.
105+ @param password string. The user's password.
106+
107+ @returns Promise<void> Resolves when the verification/login flow is completed .
97108 */
98109 const loginVerify = async ( email : string , password : string ) => {
99110 setIsLoading ( true )
@@ -109,6 +120,7 @@ export default function Authenticator({ onAuthSuccess }: AuthenticatorProps) {
109120 setIsLoading ( false )
110121 if ( response . auth_code === 200 ) {
111122 setNeedCode ( response . confirmation_required )
123+ setNeedCoolDown ( response . confirmation_required )
112124 if ( ! response . confirmation_required ) {
113125 showSuccessNotification ( 'Registration Successful!' )
114126 setActiveTab ( 'login' )
@@ -202,11 +214,11 @@ export default function Authenticator({ onAuthSuccess }: AuthenticatorProps) {
202214 }
203215
204216 /*
205- Handle form submission for user authentication.
206-
207- @param e Type: React.FormEvent. The form submit event.
208-
209- @returns Promise<void> Resolves after submit handling is complete .
217+ Handle form submission for user authentication (login or register) .
218+
219+ @param e React.FormEvent. The form submit event.
220+
221+ @returns Promise<void> Resolves after submit handling completes .
210222 */
211223 const handleSubmit = async ( e : React . FormEvent ) => {
212224 e . preventDefault ( )
@@ -231,10 +243,10 @@ export default function Authenticator({ onAuthSuccess }: AuthenticatorProps) {
231243
232244 /*
233245 Switch between login and register tabs.
234-
235- @param event Type: React.SyntheticEvent. The tab change event.
236- @param value Type: 'login' | 'register'. The target tab value.
237-
246+
247+ @param event React.SyntheticEvent. The tab change event.
248+ @param value 'login' | 'register'. The target tab value to activate .
249+
238250 @returns void
239251 */
240252 const handleTabChange = (
@@ -244,11 +256,11 @@ export default function Authenticator({ onAuthSuccess }: AuthenticatorProps) {
244256 setActiveTab ( value )
245257 }
246258 /*
247- Submit the verification code in register flow.
248-
249- @param inputCode Type: string. The 6-digit verification code.
250-
251- @returns Promise<void> Resolves when the action completes.
259+ Submit the verification code during the registration flow.
260+
261+ @param inputCode string. The 6-digit verification code provided by the user .
262+
263+ @returns Promise<void> Resolves when the verification handling completes.
252264 */
253265 const handleCodeSubmit = async ( inputCode : string ) => {
254266 setCodeErrorMessage ( '' )
@@ -288,6 +300,20 @@ export default function Authenticator({ onAuthSuccess }: AuthenticatorProps) {
288300 }
289301 }
290302
303+ /*
304+ Request sending or resending a verification code to the provided email.
305+
306+ No action is taken if the email field is empty.
307+
308+ @returns Promise<void> Resolves after the resend request completes.
309+ */
310+ const handleNeedCode = async ( ) => {
311+ if ( ! email ) {
312+ return
313+ }
314+ setNeedCode ( true )
315+ }
316+
291317 const buttonText = ( ( ) => {
292318 if ( activeTab === 'login' ) {
293319 return isLoading ? t ( 'auth.signingIn' ) : t ( 'auth.signIn' )
@@ -504,7 +530,24 @@ export default function Authenticator({ onAuthSuccess }: AuthenticatorProps) {
504530 </ button >
505531 </ div >
506532 { /** code */ }
507-
533+ < div
534+ style = { {
535+ display : 'flex' ,
536+ alignItems : 'center' ,
537+ justifyContent : 'end' ,
538+ color : '#fff' ,
539+ fontSize : '14px' ,
540+ fontWeight : '500' ,
541+ marginBottom : '16px' ,
542+ textAlign : 'left' ,
543+ cursor : 'pointer' ,
544+ } }
545+ onClick = { handleNeedCode }
546+ >
547+ < GloTooltip content = { t ( 'auth.enterTheVerificationCodeDescription' ) } >
548+ < div > { t ( 'auth.needToEnterTheVerificationCode' ) } </ div >
549+ </ GloTooltip >
550+ </ div >
508551 { /* Sign In Button */ }
509552 < button
510553 type = "submit"
@@ -543,6 +586,7 @@ export default function Authenticator({ onAuthSuccess }: AuthenticatorProps) {
543586 onSubmit = { handleCodeSubmit }
544587 isSubmitting = { isLoading }
545588 errorMessage = { codeErrorMessage }
589+ needCoolDown = { needCoolDown }
546590 />
547591 </ div >
548592 )
0 commit comments