Skip to content

Commit efdd4d6

Browse files
committed
fix(mobile): add PIN verification flow to password reset
1 parent 5132394 commit efdd4d6

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

apps/mobile/v1/src/screens/AuthScreen.tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import {
1616
import { SafeAreaView } from 'react-native-safe-area-context';
1717
import { useSignIn, useSignUp } from '@clerk/clerk-expo';
1818
import { useTheme } from '../theme';
19-
import { Button } from '../components/ui/Button';
20-
import { Input } from '../components/ui/Input';
19+
import { Button , Input } from '@/src/components/ui';
2120
import { Ionicons } from '@expo/vector-icons';
2221
import { logger } from '../lib/logger';
2322

@@ -42,7 +41,7 @@ interface ClerkUpdateParams {
4241
* Type for Clerk error objects
4342
*/
4443
interface ClerkError {
45-
errors?: Array<{ message?: string }>;
44+
errors?: { message?: string }[];
4645
}
4746

4847
/**
@@ -161,7 +160,7 @@ export default function AuthScreen() {
161160
message = 'Email or password is incorrect';
162161
}
163162

164-
logger.error('Sign in failed', err, {
163+
logger.error('Sign in failed', err as Error, {
165164
attributes: {
166165
email,
167166
errorMessage: originalMessage,
@@ -185,7 +184,7 @@ export default function AuthScreen() {
185184

186185
try {
187186
// Create sign up with all required fields including legal acceptance
188-
const result = await signUp.create({
187+
await signUp.create({
189188
emailAddress: email,
190189
password,
191190
firstName,
@@ -215,7 +214,7 @@ export default function AuthScreen() {
215214
message = 'Unable to create account';
216215
}
217216

218-
logger.error('Sign up failed', err, {
217+
logger.error('Sign up failed', err as Error, {
219218
attributes: {
220219
email,
221220
firstName,
@@ -246,15 +245,15 @@ export default function AuthScreen() {
246245
await signUp.update({
247246
legalAccepted: true,
248247
} as ClerkUpdateParams);
249-
} catch (err1: unknown) {
248+
} catch {
250249
try {
251250
// Approach 2: Update with legalAcceptedAt timestamp
252251
await signUp.update({
253252
legalAcceptedAt: new Date().getTime(),
254253
} as ClerkUpdateParams);
255254
} catch (err2: unknown) {
256255
if (__DEV__) {
257-
const error = err2 as { errors?: Array<{ message?: string }> };
256+
const error = err2 as { errors?: { message?: string }[] };
258257
console.log('Legal update error:', error.errors?.[0]?.message);
259258
}
260259
}
@@ -285,7 +284,7 @@ export default function AuthScreen() {
285284
} catch (err: unknown) {
286285
const error = err as ClerkError;
287286
const message = error.errors?.[0]?.message || 'Invalid verification code';
288-
logger.error('Email verification failed', err, {
287+
logger.error('Email verification failed', err as Error, {
289288
attributes: {
290289
email,
291290
errorMessage: message,
@@ -374,7 +373,7 @@ export default function AuthScreen() {
374373
const message = error.errors?.[0]?.message || 'Failed to send reset code';
375374
setErrorMessage(message);
376375
showToast(message);
377-
logger.error('Password reset code send failed', err, {
376+
logger.error('Password reset code send failed', err as Error, {
378377
attributes: { email },
379378
});
380379
} finally {
@@ -410,7 +409,7 @@ export default function AuthScreen() {
410409
const message = error.errors?.[0]?.message || 'Invalid reset code';
411410
setErrorMessage(message);
412411
showToast(message);
413-
logger.error('Password reset code verification failed', err, {
412+
logger.error('Password reset code verification failed', err as Error, {
414413
attributes: { email },
415414
});
416415
} finally {
@@ -424,6 +423,17 @@ export default function AuthScreen() {
424423
const handleCompletePasswordReset = async () => {
425424
if (!signInLoaded) return;
426425

426+
// Security: Verify PIN was validated before allowing password reset
427+
if (!resetPasswordVerified) {
428+
const message = 'Please verify your reset code first';
429+
setErrorMessage(message);
430+
showToast(message);
431+
logger.warn('Attempted password reset without PIN verification', {
432+
attributes: { email },
433+
});
434+
return;
435+
}
436+
427437
if (!newPassword.trim()) {
428438
const message = 'Please enter a new password';
429439
setErrorMessage(message);
@@ -460,7 +470,7 @@ export default function AuthScreen() {
460470
const message = error.errors?.[0]?.message || 'Failed to reset password';
461471
setErrorMessage(message);
462472
showToast(message);
463-
logger.error('Password reset completion failed', err, {
473+
logger.error('Password reset completion failed', err as Error, {
464474
attributes: { email },
465475
});
466476
} finally {
@@ -1100,4 +1110,4 @@ const styles = StyleSheet.create({
11001110
width: 1,
11011111
height: 1,
11021112
},
1103-
});
1113+
});

0 commit comments

Comments
 (0)