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

Enhancements #6

Merged
merged 7 commits into from
Sep 11, 2024
Merged

Enhancements #6

merged 7 commits into from
Sep 11, 2024

Conversation

DanielRivers
Copy link
Contributor

Explain your changes

  • Wait for expo to be loaded before using
  • non crypto support for random string generator
  • support external nonce generator and removes redundant random generator calls.

Checklist

🛟 If you need help, consider asking for advice over in the Kinde community.

Copy link
Contributor

coderabbitai bot commented Sep 11, 2024

Warning

Rate limit exceeded

@DanielRivers has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 6 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between bdf06f4 and 3eb0cec.

Walkthrough

The changes introduce several enhancements across multiple files. A new asynchronous function, waitForExpoSecureStore, ensures the expoSecureStore is initialized before executing related methods. The LoginOptions type is updated to include a nonce property for security against replay attacks. The generateAuthUrl function is modified to conditionally handle state and nonce parameters, allowing user-defined values. Lastly, the generateRandomString function is improved with a fallback mechanism for environments lacking the crypto API, introducing a non-cryptographic random string generation method.

Changes

File Change Summary
lib/sessionManager/stores/expoSecureStore.ts Added waitForExpoSecureStore function; modified setSessionItem, getSessionItem, and removeSessionItem to call this new function. Updated getSessionItem to return null for empty strings.
lib/types.ts Added nonce?: string to LoginOptions type for enhanced security; minor formatting change in LoginMethodParams.
lib/utils/generateAuthUrl.ts Modified generateAuthUrl to conditionally handle options.state and options.nonce, allowing for user-defined values instead of unconditional random generation.
lib/utils/generateRandomString.ts Enhanced generateRandomString to check for crypto availability and added generateRandomStringNonCrypto function for environments without crypto, ensuring consistent random string generation across different contexts.

Possibly related PRs

  • feat: add expo-secure-store #5: The changes in the main PR are directly related to the expoSecureStore functionality, as both involve the ExpoSecureStore class and its methods for managing session items. The main PR introduces a new asynchronous function and modifies existing methods in the ExpoSecureStore, while the retrieved PR adds support for the expo-secure-store session store, enhancing its capabilities.

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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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: 0

Outside diff range and nitpick comments (5)
lib/utils/generateRandomString.ts (1)

20-30: LGTM, but consider adding a comment.

The generateRandomStringNonCrypto function is a useful addition for generating random strings in environments where the crypto API is not available.

To improve the code clarity, consider adding a comment to clarify that the function is not suitable for cryptographic purposes:

+/**
+ * Generates a random string using a non-cryptographic method.
+ * Note: This function is not suitable for cryptographic purposes.
+ * @param {number} length
+ * @returns {string} random string
+ */
function generateRandomStringNonCrypto(length: number = 28) {
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let result = '';
  const charactersLength = characters.length;

  for (let i = 0; i < length; i++) {
    result += characters.charAt(Math.floor(Math.random() * charactersLength));
  }
  
  return result;
}
lib/sessionManager/stores/expoSecureStore.ts (4)

7-14: LGTM! Consider making the retry limit and delay configurable.

The waitForExpoSecureStore function is correctly implemented and serves its purpose of ensuring that expoSecureStore is initialized before executing related methods.

The retry limit of 20 and the delay of 100 milliseconds are reasonable values for most use cases.

Consider making the retry limit and delay configurable by accepting them as optional parameters with default values:

async function waitForExpoSecureStore(maxRetries = 20, retryDelay = 100) {
  let tries = 0;
  while (!expoSecureStore && tries < maxRetries) {
    console.log('waiting');
    await new Promise((resolve) => setTimeout(resolve, retryDelay));
    tries++;
  }
}

54-54: LGTM! Consider handling the case where expoSecureStore is not initialized.

The setSessionItem method is correctly updated to ensure that expoSecureStore is initialized before executing its core logic.

Consider handling the case where expoSecureStore is not initialized even after the maximum number of retries:

async setSessionItem(
  itemKey: V | StorageKeys,
  itemValue: unknown,
): Promise<void> {
  await waitForExpoSecureStore();
  if (!expoSecureStore) {
    throw new Error("ExpoSecureStore is not initialized");
  }
  // rest of the method
}

Line range hint 79-97: LGTM! Consider handling the case where expoSecureStore is not initialized.

The getSessionItem method is correctly updated to ensure that expoSecureStore is initialized before executing its core logic.

The change to return null if the joined string is empty is a good improvement for consistency.

Consider handling the case where expoSecureStore is not initialized even after the maximum number of retries:

async getSessionItem(itemKey: V | StorageKeys): Promise<unknown | null> {
  await waitForExpoSecureStore();
  if (!expoSecureStore) {
    throw new Error("ExpoSecureStore is not initialized");
  }
  // rest of the method
}

106-107: LGTM! Consider handling the case where expoSecureStore is not initialized.

The removeSessionItem method is correctly updated to ensure that expoSecureStore is initialized before executing its core logic.

Consider handling the case where expoSecureStore is not initialized even after the maximum number of retries:

async removeSessionItem(itemKey: V | StorageKeys): Promise<void> {
  await waitForExpoSecureStore();
  if (!expoSecureStore) {
    throw new Error("ExpoSecureStore is not initialized");
  }
  // rest of the method
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a177a01 and 80d76c4.

Files selected for processing (4)
  • lib/sessionManager/stores/expoSecureStore.ts (5 hunks)
  • lib/types.ts (2 hunks)
  • lib/utils/generateAuthUrl.ts (1 hunks)
  • lib/utils/generateRandomString.ts (1 hunks)
Additional comments not posted (4)
lib/utils/generateRandomString.ts (1)

7-13: LGTM!

The changes to the generateRandomString function are approved. The introduction of a fallback mechanism using the generateRandomStringNonCrypto function enhances the function's robustness and usability across different environments.

lib/utils/generateAuthUrl.ts (2)

25-27: LGTM!

The changes to conditionally handle the state parameter are approved. This allows the user to provide their own state value while maintaining the fallback to a securely generated random string.


30-33: LGTM!

The changes to conditionally handle the nonce parameter are approved. This allows the user to provide their own nonce value while maintaining the fallback to a securely generated random string. Including the nonce in the searchParams object is also correct.

lib/types.ts (1)

108-111: LGTM!

The addition of the optional nonce property to the LoginOptions type is a valuable security enhancement. The accompanying comment clearly explains its purpose as a single-use code to prevent replay attacks.

The code changes are approved.

@DanielRivers DanielRivers merged commit 0181a78 into main Sep 11, 2024
1 check passed
@DanielRivers DanielRivers deleted the feat/enhancements branch September 11, 2024 18:57
Copy link

codecov bot commented Sep 11, 2024

Codecov Report

Attention: Patch coverage is 43.90244% with 23 lines in your changes missing coverage. Please review.

Project coverage is 59.30%. Comparing base (a177a01) to head (3eb0cec).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
lib/utils/generateRandomString.ts 29.41% 12 Missing ⚠️
lib/sessionManager/stores/expoSecureStore.ts 0.00% 11 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main       #6      +/-   ##
==========================================
- Coverage   62.17%   59.30%   -2.88%     
==========================================
  Files          15       15              
  Lines         312      344      +32     
  Branches       36       37       +1     
==========================================
+ Hits          194      204      +10     
- Misses        118      140      +22     
Files with missing lines Coverage Δ
lib/types.ts 100.00% <ø> (ø)
lib/utils/generateAuthUrl.ts 100.00% <100.00%> (ø)
lib/sessionManager/stores/expoSecureStore.ts 14.81% <0.00%> (-2.09%) ⬇️
lib/utils/generateRandomString.ts 45.45% <29.41%> (-54.55%) ⬇️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant