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

Fixes undefined config variables in standalone builds leading to crashes #7

Merged

Conversation

didley
Copy link
Contributor

@didley didley commented Nov 11, 2024

Explain your changes

This PR passes configuration variables via a KindeAuthProvider config prop rather than accessing them internally via process.env.

We were having issues with this lib working fine locally but crashing within a standalone build, such as TestFlight or a simulator build, when login or register is called.

It appears to be due to how expo handles EXPO_PUBLIC_ variables. As noted in the expo docs, EXPO_PUBLIC_ variables are replaced in your code but not within node_modules. Though node_modules EXPO_PUBLIC_ variables appear to load when running your project locally.

I've deployed this to a private package for testing with an iOS simulator build and it has fixed our issue.

May fix issue #4

Checklist

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

Copy link

coderabbitai bot commented Nov 11, 2024

Walkthrough

The changes in this pull request primarily involve the KindeAuthProvider component and its documentation. The component now accepts a config prop for configuration, replacing the previous reliance on environment variables. This prop requires domain and clientId, with scopes being optional. Error handling for missing configuration values has been added. The readme.md file has been updated to reflect these changes, removing the environment variable instructions and providing examples of the new inline configuration method.

Changes

File Change Summary
lib/KindeAuthProvider.tsx Updated KindeAuthProvider to accept a config prop, enhancing error handling and configuration management.
readme.md Revised installation instructions and configuration setup for KindeAuthProvider, removing environment variables.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant KindeAuthProvider
    participant Environment

    Developer->>KindeAuthProvider: Pass config { domain, clientId, scopes }
    KindeAuthProvider->>KindeAuthProvider: Validate config values
    KindeAuthProvider->>KindeAuthProvider: Initialize authentication
    KindeAuthProvider->>Environment: Use domain and clientId for auth
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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.

@didley
Copy link
Contributor Author

didley commented Nov 11, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Nov 11, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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 (4)
readme.md (2)

26-31: LGTM! The new configuration approach is well documented.

The inline configuration with clear comments about required and optional props provides a better developer experience.

Consider adding a brief explanation about why this approach is preferred over environment variables, particularly for standalone builds. This would help developers understand the rationale behind the change.

 <KindeAuthProvider config={{
    domain: "your-app.kinde.com", // Required
    clientId: "your-client-id", // Required
    // Optional (default: "openid profile email offline")
    scopes: "openid profile email offline",
+ }}>
+   {/* 
+    * Note: Direct configuration is recommended over environment variables
+    * to ensure proper functionality in standalone builds (e.g., TestFlight, simulators)
+    */}
    <!-- Your application code -->

Line range hint 11-13: Remove or update the "Environment variables" section.

The "Environment variables" section is now empty and only contains information about the redirect URL. Since the SDK no longer uses environment variables for configuration, this section should either be removed or updated to focus solely on the redirect URL functionality.

Consider either:

  1. Removing the section entirely, or
  2. Renaming it to "Redirect URL Configuration" and moving the redirect URL information there
lib/KindeAuthProvider.tsx (2)

47-54: Enhance error messages with setup instructions.

While the validation is correct, the error messages could be more helpful by including setup instructions.

Consider updating the error messages:

-    throw new Error("KindeAuthProvider config.domain prop is undefined");
+    throw new Error(
+      "KindeAuthProvider config.domain prop is undefined. " +
+      "Please provide a valid domain in the KindeAuthProvider config prop. " +
+      "Example: <KindeAuthProvider config={{ domain: 'https://your-domain.kinde.com' }}>"
+    );

-    throw new Error("KindeAuthProvider config.clientId prop is undefined");
+    throw new Error(
+      "KindeAuthProvider config.clientId prop is undefined. " +
+      "Please provide a valid clientId in the KindeAuthProvider config prop. " +
+      "Example: <KindeAuthProvider config={{ clientId: 'your_client_id' }}>"
+    );

55-55: Optimize scopes initialization.

The current implementation performs the split(" ") operation twice when config.scopes is undefined.

Consider this more efficient approach:

-  const scopes = config.scopes?.split(" ") || DEFAULT_TOKEN_SCOPES.split(" ");
+  const scopesString = config.scopes || DEFAULT_TOKEN_SCOPES;
+  const scopes = scopesString.split(" ");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5124993 and 256cbdf.

📒 Files selected for processing (2)
  • lib/KindeAuthProvider.tsx (1 hunks)
  • readme.md (1 hunks)
🧰 Additional context used
📓 Learnings (1)
lib/KindeAuthProvider.tsx (1)
Learnt from: didley
PR: kinde-oss/expo#5
File: lib/KindeAuthProvider.tsx:38-45
Timestamp: 2024-11-08T06:21:44.638Z
Learning: In `lib/KindeAuthProvider.tsx`, for the `KindeAuthProvider` component, the `config.domain` and `config.clientId` properties should be typed as `string | undefined` because users may pass `process.env` values, which can be `undefined`.
🔇 Additional comments (2)
lib/KindeAuthProvider.tsx (2)

38-45: LGTM! Well-structured config prop type definition.

The type definition correctly implements string | undefined for domain and clientId, which is appropriate for handling potential process.env values. The optional scopes field provides good flexibility.


38-55: Verify removal of process.env usage.

The implementation successfully moves configuration to props. Let's verify that all process.env usages have been removed.

✅ Verification successful

All process.env references successfully removed

The verification confirms that all process.env references related to Kinde configuration have been successfully removed from the codebase. The only remaining references are the error messages for validation of the new config props, which is the expected behavior after the migration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining process.env usage related to Kinde configuration

# Search for process.env usage
echo "Checking for process.env usage..."
rg -i "process\.env\.(EXPO_PUBLIC_KINDE|KINDE)" 

# Search for environment variable documentation
echo "Checking for environment variable documentation..."
rg -i "(EXPO_PUBLIC_KINDE|KINDE)_(DOMAIN|CLIENT_ID|SCOPES)"

Length of output: 299


Script:

#!/bin/bash
# Let's try a broader search to catch any remaining process.env usage
# and environment variables related to authentication configuration

# Search for process.env usage in the codebase
echo "Checking for any process.env usage..."
rg "process\.env" -A 2 -B 2

# Search for environment-related terms in documentation files
echo "Checking documentation files..."
fd -e md -e mdx -x cat {} \; | rg -i "(environment|env|KINDE|configuration)"

# Search for potential configuration patterns
echo "Checking for configuration patterns..."
rg "(KINDE|CLIENT_ID|AUTH.*DOMAIN)" -A 2 -B 2

Length of output: 1934


Script:

#!/bin/bash
# Let's do a more focused search in the lib directory and test files
# to ensure complete removal of environment variables

# Check the lib directory specifically
echo "Checking lib directory..."
fd . lib -t f -x cat {} \; | rg -i "(process\.env|KINDE.*CLIENT|KINDE.*DOMAIN)"

# Check test files for any remaining env references
echo "Checking test files..."
fd -e test.tsx -e test.ts -e spec.tsx -e spec.ts -x cat {} \; | rg -i "(process\.env|KINDE.*CLIENT|KINDE.*DOMAIN)"

# Check for any environment setup files
echo "Checking environment setup files..."
fd -e env -e env.example -e env.local -x cat {} \;

Length of output: 607

@DanielRivers DanielRivers merged commit 42cc387 into kinde-oss:main Dec 18, 2024
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.

2 participants