Commit 1b329d2
authored
chore: Abstract turn off remember me function into auth hook (MetaMask#23917)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
This PR centralizes authentication-related operations by introducing a
new `useAuthentication` hook in the `app/core/Authentication/`
directory. The hook encapsulates the logic for turning off the "Remember
Me" feature and locking the app, which was previously scattered directly
in the `TurnOffRememberMeModal` component.
**Reason for the change:**
- Authentication logic was directly embedded in UI components, making it
difficult to reuse and test
- Redux dispatch calls and Authentication service calls were mixed with
component logic
- No centralized place for authentication-related operations
**Improvement/Solution:**
- Created `useAuthentication` hook that combines Redux action
dispatching with Authentication service calls
- Moved `turnOffRememberMeAndLockApp` logic from
`TurnOffRememberMeModal` to the new hook
- Updated `TurnOffRememberMeModal` to use the centralized hook instead
of direct dispatch and service calls
- Added comprehensive unit test coverage (12 tests) following project
testing guidelines
- Hook is exported from `app/core/Authentication/index.ts` for easy
consumption
This change improves code organization, testability, and reusability of
authentication features across the application.
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: Turn off Remember Me and lock app
Scenario: user turns off Remember Me feature
Given the user has "Remember Me" enabled and is logged into the app
And the user navigates to the Turn Off Remember Me modal
When user enters their password correctly
And user taps the "Turn Off Remember Me" button
Then the "Remember Me" feature is disabled
And the app is locked
And the user is redirected to the login screen
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Modernizes auth flows and centralizes logic while tightening tests.
>
> - API change: `Authentication.updateAuthPreference` now accepts `{
authType, password }`; all callers updated (`TurnOffRememberMeModal`,
`LoginOptionsSettings`, `RememberMeOptionSection`, related tests)
> - New `useAuthentication` hook (exported via
`core/Authentication/index.ts`) with unit tests; provides `lockApp`
> - `TurnOffRememberMeModal`: simplifies disable flow, restores previous
auth with entered password, clears stored state, updates Redux, and
removes direct `lockApp` calls; improves loading handling with `act`
> - Authentication internals: `componentAuthenticationType` prioritizes
`REMEMBER_ME`, uses `PASSCODE_DISABLED` to infer BIOMETRIC/PASSCODE, and
`storePassword` now dispatches `passwordSet`; removed lock-time side
effects; `lockApp` gains `allowRememberMe` control and ordering tests
> - Expanded tests across settings sections to cover password-required
flows, callbacks, mutual exclusivity, and error handling
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
d511fa8. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 4c40232 commit 1b329d2
11 files changed
Lines changed: 649 additions & 246 deletions
File tree
- app
- components
- UI/TurnOffRememberMeModal
- Views/Settings/SecuritySettings/Sections
- core/Authentication
- hooks
Lines changed: 95 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | | - | |
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
46 | 68 | | |
47 | 69 | | |
48 | 70 | | |
| |||
204 | 226 | | |
205 | 227 | | |
206 | 228 | | |
207 | | - | |
208 | | - | |
209 | 229 | | |
210 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
211 | 258 | | |
212 | 259 | | |
213 | 260 | | |
214 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
215 | 266 | | |
216 | 267 | | |
217 | 268 | | |
218 | 269 | | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | 270 | | |
225 | 271 | | |
226 | 272 | | |
227 | 273 | | |
228 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
229 | 282 | | |
| 283 | + | |
230 | 284 | | |
231 | 285 | | |
232 | 286 | | |
233 | 287 | | |
234 | | - | |
235 | 288 | | |
236 | 289 | | |
237 | 290 | | |
| |||
308 | 361 | | |
309 | 362 | | |
310 | 363 | | |
311 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
312 | 367 | | |
313 | 368 | | |
314 | 369 | | |
315 | 370 | | |
316 | 371 | | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
321 | 376 | | |
322 | 377 | | |
323 | 378 | | |
324 | | - | |
325 | 379 | | |
326 | 380 | | |
327 | 381 | | |
| |||
343 | 397 | | |
344 | 398 | | |
345 | 399 | | |
346 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
347 | 403 | | |
348 | 404 | | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
353 | 409 | | |
354 | 410 | | |
355 | 411 | | |
| |||
374 | 430 | | |
375 | 431 | | |
376 | 432 | | |
377 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
378 | 436 | | |
379 | 437 | | |
380 | 438 | | |
| |||
387 | 445 | | |
388 | 446 | | |
389 | 447 | | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | 448 | | |
394 | 449 | | |
395 | 450 | | |
| |||
414 | 469 | | |
415 | 470 | | |
416 | 471 | | |
417 | | - | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
418 | 475 | | |
419 | 476 | | |
420 | 477 | | |
| |||
427 | 484 | | |
428 | 485 | | |
429 | 486 | | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | 487 | | |
434 | 488 | | |
435 | 489 | | |
| |||
450 | 504 | | |
451 | 505 | | |
452 | 506 | | |
453 | | - | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
454 | 510 | | |
455 | 511 | | |
456 | 512 | | |
457 | | - | |
458 | 513 | | |
459 | 514 | | |
460 | 515 | | |
| |||
480 | 535 | | |
481 | 536 | | |
482 | 537 | | |
483 | | - | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
484 | 541 | | |
485 | 542 | | |
486 | 543 | | |
| |||
512 | 569 | | |
513 | 570 | | |
514 | 571 | | |
515 | | - | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
516 | 575 | | |
517 | 576 | | |
518 | 577 | | |
519 | | - | |
520 | 578 | | |
521 | 579 | | |
522 | 580 | | |
| |||
Lines changed: 6 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | | - | |
| 103 | + | |
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
| |||
111 | 110 | | |
112 | 111 | | |
113 | 112 | | |
114 | | - | |
| 113 | + | |
115 | 114 | | |
116 | 115 | | |
117 | 116 | | |
| |||
Lines changed: 22 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
206 | | - | |
207 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
238 | | - | |
239 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
| |||
510 | 510 | | |
511 | 511 | | |
512 | 512 | | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
| |||
607 | 607 | | |
608 | 608 | | |
609 | 609 | | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
614 | 614 | | |
615 | 615 | | |
616 | 616 | | |
| |||
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
666 | 666 | | |
667 | 667 | | |
668 | 668 | | |
| |||
0 commit comments