feat(CLI): implement better auth detection#189
Conversation
|
@anirudhprmar is attempting to deploy a commit to the maxktz Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe PayKit CLI initialization command now detects the presence of Better Auth in the target project and conditionally generates an identity-resolving handler in the PayKit config file. A new detection utility identifies Better Auth; a shared helper function centralizes identity block generation; and the initialization flow integrates both to emit config with optional Better Auth session integration. ChangesBetter Auth Identity Integration
Sequence DiagramsequenceDiagram
participant initAction as initAction
participant detectBA as detectBetterAuth
participant locateCfg as locate Better Auth config
participant genCfg as generateConfigFile
participant writeFile as write config file
initAction->>detectBA: check for better-auth
detectBA-->>initAction: usesBetterAuth (boolean)
initAction->>locateCfg: find Better Auth config path
locateCfg-->>initAction: auth import path or undefined
initAction->>genCfg: pass usesBetterAuth & auth path
genCfg-->>initAction: PayKit config string
initAction->>writeFile: write config with conditional auth integration
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/paykit/src/cli/commands/init.ts`:
- Around line 566-568: The ternary expression using usesBetterAuth &&
existingBetterAuthConfig ? p.log.step(`Detected Better Auth:
${picocolors.bold(existingBetterAuthConfig)}`) : null is being used for a
side-effect and triggers the no-unused-expressions ESLint rule; replace it with
a straightforward if statement: check if usesBetterAuth &&
existingBetterAuthConfig then call p.log.step(...) so the side-effect is
explicit (refer to usesBetterAuth, existingBetterAuthConfig and p.log.step in
init.ts).
- Line 211: The generated import line includes a stray semicolon inside the
import path string (the template expression using includeIdentify and
useBetterAuthIdentify produces `import { auth } from
"${useBetterAuthIdentify};"`), causing a syntax error; update the template so
the semicolon is placed after the closing quote (or removed from inside the
string) so it emits `import { auth } from "${useBetterAuthIdentify}";` (or
without a semicolon if your style prefers), adjusting the template expression
that builds the import line where includeIdentify and useBetterAuthIdentify are
used.
- Line 151: The import template places the semicolon inside the string,
producing an invalid path; update the conditional template that builds the
import line (using the includeIdentify and useBetterAuthIdentify variables) so
the semicolon is outside the quoted path — e.g., change the generated fragment
from `import { auth } from "${useBetterAuthIdentify};"` to `import { auth } from
"${useBetterAuthIdentify}";` so the module specifier is correct and the import
statement ends with a semicolon.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9029ddb9-9e98-4bd5-9255-48e0081b74f2
📒 Files selected for processing (2)
packages/paykit/src/cli/commands/init.tspackages/paykit/src/cli/utils/detect.ts
|
|
||
| return `${providerImport(provider)} | ||
| import { createPayKit } from "paykitjs";${importLine} | ||
| ${includeIdentify && useBetterAuthIdentify ? `import { auth } from "${useBetterAuthIdentify};"` : ""} |
There was a problem hiding this comment.
Syntax error: semicolon inside the import path string.
The semicolon is placed inside the quotes, generating an invalid import like import { auth } from "path/to/auth;" instead of import { auth } from "path/to/auth";. This will cause a module resolution failure.
🐛 Proposed fix
-${includeIdentify && useBetterAuthIdentify ? `import { auth } from "${useBetterAuthIdentify};"` : ""}
+${includeIdentify && useBetterAuthIdentify ? `import { auth } from "${useBetterAuthIdentify}";` : ""}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ${includeIdentify && useBetterAuthIdentify ? `import { auth } from "${useBetterAuthIdentify};"` : ""} | |
| ${includeIdentify && useBetterAuthIdentify ? `import { auth } from "${useBetterAuthIdentify}";` : ""} |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/paykit/src/cli/commands/init.ts` at line 151, The import template
places the semicolon inside the string, producing an invalid path; update the
conditional template that builds the import line (using the includeIdentify and
useBetterAuthIdentify variables) so the semicolon is outside the quoted path —
e.g., change the generated fragment from `import { auth } from
"${useBetterAuthIdentify};"` to `import { auth } from
"${useBetterAuthIdentify}";` so the module specifier is correct and the import
statement ends with a semicolon.
|
|
||
| return `${providerImport(provider)} | ||
| import { createPayKit } from "paykitjs";${importLine} | ||
| ${includeIdentify && useBetterAuthIdentify ? `import { auth } from "${useBetterAuthIdentify};"` : ""} |
There was a problem hiding this comment.
Same syntax error: semicolon inside the import path string.
Same issue as line 151 — the semicolon is inside the quotes.
🐛 Proposed fix
-${includeIdentify && useBetterAuthIdentify ? `import { auth } from "${useBetterAuthIdentify};"` : ""}
+${includeIdentify && useBetterAuthIdentify ? `import { auth } from "${useBetterAuthIdentify}";` : ""}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ${includeIdentify && useBetterAuthIdentify ? `import { auth } from "${useBetterAuthIdentify};"` : ""} | |
| ${includeIdentify && useBetterAuthIdentify ? `import { auth } from "${useBetterAuthIdentify}";` : ""} |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/paykit/src/cli/commands/init.ts` at line 211, The generated import
line includes a stray semicolon inside the import path string (the template
expression using includeIdentify and useBetterAuthIdentify produces `import {
auth } from "${useBetterAuthIdentify};"`), causing a syntax error; update the
template so the semicolon is placed after the closing quote (or removed from
inside the string) so it emits `import { auth } from
"${useBetterAuthIdentify}";` (or without a semicolon if your style prefers),
adjusting the template expression that builds the import line where
includeIdentify and useBetterAuthIdentify are used.
| usesBetterAuth && existingBetterAuthConfig | ||
| ? p.log.step(`Detected Better Auth: ${picocolors.bold(existingBetterAuthConfig)}`) | ||
| : null; |
There was a problem hiding this comment.
Use if statement instead of ternary for side effects.
ESLint reports no-unused-expressions. The ternary result is discarded — use an if statement for clarity and to satisfy the linter.
🔧 Proposed fix
- usesBetterAuth && existingBetterAuthConfig
- ? p.log.step(`Detected Better Auth: ${picocolors.bold(existingBetterAuthConfig)}`)
- : null;
+ if (usesBetterAuth && existingBetterAuthConfig) {
+ p.log.step(`Detected Better Auth: ${picocolors.bold(existingBetterAuthConfig)}`);
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| usesBetterAuth && existingBetterAuthConfig | |
| ? p.log.step(`Detected Better Auth: ${picocolors.bold(existingBetterAuthConfig)}`) | |
| : null; | |
| if (usesBetterAuth && existingBetterAuthConfig) { | |
| p.log.step(`Detected Better Auth: ${picocolors.bold(existingBetterAuthConfig)}`); | |
| } |
🧰 Tools
🪛 GitHub Check: lint
[warning] 566-568: eslint(no-unused-expressions)
Expected expression to be used
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/paykit/src/cli/commands/init.ts` around lines 566 - 568, The ternary
expression using usesBetterAuth && existingBetterAuthConfig ?
p.log.step(`Detected Better Auth: ${picocolors.bold(existingBetterAuthConfig)}`)
: null is being used for a side-effect and triggers the no-unused-expressions
ESLint rule; replace it with a straightforward if statement: check if
usesBetterAuth && existingBetterAuthConfig then call p.log.step(...) so the
side-effect is explicit (refer to usesBetterAuth, existingBetterAuthConfig and
p.log.step in init.ts).
Issue : #114
Summary
Summary by CodeRabbit