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(native-app): offline mode more fixes #15246

Merged
merged 3 commits into from
Jun 17, 2024
Merged

Conversation

thoreyjona
Copy link
Contributor

@thoreyjona thoreyjona commented Jun 14, 2024

What

  • Fix offline mode when you go offline with app open
  • Persist userInfo in app so we show it correctly when offline.
    I tried to only persist userInfo.name and userInfo.nationalId but did not find a proper way to do it (zustand whitelist only accepts keys of the store).

This is the info that is stored:
Is something of this too delicate to persist? E.g. the sub? @eirikurn

{
  "auth_01": {
    "state": {
      "userInfo": {
        "sub": "E5D3E5E081EC4BB765D25485030499577E0F5FC10A89599DBDEB5CD6231DB9BD",
        "nationalId": "0101303019",
        "subjectType": "person",
        "name": "Gervimaður Afríka",
        "gender": "male",
        "birthdate": "1930-01-01",
        "locale": "en"
      }
    },
    "version": 0
  }
}

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Enhanced authentication store with token persistency, auto-refresh, login, and logout capabilities.
    • Improved app lock screen functionality with more precise overlay dismissal using lock screen component ID.
  • Bug Fixes

    • Corrected the handling of the lockScreenActivatedAt parameter, ensuring it is set to null properly.
  • Refactor

    • Added a condition to setupEventHandlers() to improve app lock screen behavior based on lockScreenActivatedAt status.

@thoreyjona thoreyjona requested a review from a team as a code owner June 14, 2024 16:11
Copy link
Contributor

coderabbitai bot commented Jun 14, 2024

Walkthrough

The recent changes improved state persistence and streamlined app lock screen management. State persistence was implemented for user authentication in the auth-store.ts file by adding the persist middleware. The app-lock.ts file was enhanced to precisely dismiss specific lock screens using an ID. Furthermore, the setup-event-handlers.ts file now conditionally manages the app lock screen based on activation status. These enhancements lead to a more efficient and user-friendly application experience.

Changes

Files Change Summary
apps/native/app/src/stores/auth-store.ts Added persist middleware, handled token refresh, login, and logout with persistence. Configured AsyncStorage and whitelisted userInfo.
apps/native/app/src/utils/app-lock.ts Modified hideAppLockOverlay() to accept a lockScreenComponentId and dismiss specific lock screens, setting lockScreenActivatedAt to null.
apps/native/app/src/utils/lifecycle/setup-event-handlers.ts Added a condition to check if lockScreenActivatedAt is not null before calling hideAppLockOverlay(), enhancing lock screen management.

Sequence Diagram(s)

Auth Store with Persistence

sequenceDiagram
    actor User
    User->>AuthStore: Performs login/logout
    AuthStore->>PersistMiddleware: Save state to AsyncStorage
    PersistMiddleware-->>AuthStore: State saved
    AuthStore->>User: Token refreshed, User Info updated
Loading

Hide App Lock Overlay

sequenceDiagram
    participant App
    participant LockOverlay
    App->>LockOverlay: Request to hide with lockScreenComponentId
    alt lockScreenActivatedAt is not null
        LockOverlay-->>App: Dismiss specific lock screen
    else
        LockOverlay-->>App: Update with status
    end
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7b0c0f8 and 3e97df8.

Files selected for processing (3)
  • apps/native/app/src/stores/auth-store.ts (3 hunks)
  • apps/native/app/src/utils/app-lock.ts (1 hunks)
  • apps/native/app/src/utils/lifecycle/setup-event-handlers.ts (1 hunks)
Additional context used
Path-based instructions (3)
apps/native/app/src/utils/app-lock.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/native/app/src/utils/lifecycle/setup-event-handlers.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/native/app/src/stores/auth-store.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
Biome
apps/native/app/src/stores/auth-store.ts

[error] 102-107: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.

Additional comments not posted (2)
apps/native/app/src/utils/app-lock.ts (1)

58-64: The updated hideAppLockOverlay function now correctly handles the dismissal of the lock screen overlay and resets the relevant states. Good integration with the authStore state management.

apps/native/app/src/utils/lifecycle/setup-event-handlers.ts (1)

129-132: The logic to handle app lock based on the timeout and app state is well-implemented. It ensures that the app lock overlay is managed correctly across different app states.

apps/native/app/src/stores/auth-store.ts Show resolved Hide resolved
@datadog-island-is
Copy link

datadog-island-is bot commented Jun 14, 2024

Datadog Report

All test runs 1349899 🔗

13 Total Test Services: 0 Failed, 13 Passed
⬆️ Test Sessions change in coverage: 1 increased (+0.02%), 23 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.9s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 14.97s 1 no change Link
application-system-api 0 0 0 111 2 2m 30.78s 1 no change Link
application-template-api-modules 0 0 0 109 0 1m 37.18s 1 no change Link
auth-api-lib 0 0 0 19 0 54.38s 1 no change Link
services-auth-admin-api 0 0 0 106 0 3m 11.75s 1 no change Link
services-auth-delegation-api 0 0 0 254 0 3m 13.67s 1 no change Link
services-auth-ids-api 0 0 0 215 0 1m 20.67s 1 no change Link
services-auth-personal-representative 0 0 0 59 0 1m 13.98s 1 increased (+0.02%) Link
services-auth-personal-representative-public 0 0 0 10 0 31.98s 1 no change Link

Copy link

codecov bot commented Jun 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 37.10%. Comparing base (5bbf5d8) to head (3e97df8).

Current head 3e97df8 differs from pull request most recent head de03555

Please upload reports for the commit de03555 to get more accurate results.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #15246      +/-   ##
==========================================
- Coverage   37.10%   37.10%   -0.01%     
==========================================
  Files        6448     6448              
  Lines      131454   131446       -8     
  Branches    37574    37566       -8     
==========================================
- Hits        48780    48776       -4     
+ Misses      82674    82670       -4     
Flag Coverage Δ
api 3.51% <ø> (ø)
api-domains-auth-admin 54.29% <ø> (ø)
application-system-api 41.96% <ø> (ø)
application-template-api-modules 24.37% <ø> (-0.02%) ⬇️
auth-api-lib 14.30% <ø> (ø)
services-auth-admin-api 51.39% <ø> (ø)
services-auth-delegation-api 61.66% <ø> (ø)
services-auth-ids-api 54.84% <ø> (-0.02%) ⬇️
services-auth-personal-representative 48.53% <ø> (+0.03%) ⬆️
services-auth-personal-representative-public 44.42% <ø> (ø)
services-auth-public-api 50.46% <ø> (ø)
services-user-notification 47.61% <ø> (+0.02%) ⬆️
services-user-profile 62.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5bbf5d8...de03555. Read the comment docs.

@thoreyjona thoreyjona added the automerge Merge this PR as soon as all checks pass label Jun 14, 2024
Copy link

@heita-is heita-is left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome nice catch on the dismiss overlay 😅

@kodiakhq kodiakhq bot merged commit f95ab14 into main Jun 17, 2024
23 checks passed
@kodiakhq kodiakhq bot deleted the feat/offline-mode-more-fixes branch June 17, 2024 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants