Skip to content

Conversation

@sean-brydon
Copy link
Member

What does this PR do?

This PR extracts the credentials provider authorization logic from the NextAuth provider configuration into a separate, testable function. This enables comprehensive unit testing of the authorization flow, particularly the simplified password validation logic introduced in PR #25563.

@sean-brydon sean-brydon requested a review from a team as a code owner December 3, 2025 09:35
@graphite-app graphite-app bot requested a review from a team December 3, 2025 09:35
totpCode: { label: "Two-factor Code", type: "input", placeholder: "Code from authenticator app" },
backupCode: { label: "Backup Code", type: "input", placeholder: "Two-factor backup code" },
},
async authorize(credentials): Promise<User | null> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Extract this function to "authoriseCredentials" so we can test easier without logic being caught be AuthJS credential provider

authorize: authorizeCredentials,
});

const providers: Provider[] = [calComCredentialsProvider, ImpersonationProvider];
Copy link
Member Author

Choose a reason for hiding this comment

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

use the provider tsame as before

emrysal
emrysal previously approved these changes Dec 3, 2025
Copy link
Contributor

@emrysal emrysal left a comment

Choose a reason for hiding this comment

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

lgtm, let's start refactoring this straight away indeed.

@emrysal emrysal enabled auto-merge (squash) December 3, 2025 09:38
@vercel
Copy link

vercel bot commented Dec 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
cal-companion Error Error Dec 3, 2025 9:49am
2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Dec 3, 2025 9:49am
cal-eu Ignored Ignored Dec 3, 2025 9:49am

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/features/auth/lib/next-auth-options.ts">

<violation number="1" location="packages/features/auth/lib/next-auth-options.ts:143">
P1: Rule violated: **Avoid Logging Sensitive Information**

`authorizeCredentials` logs the entire credentials payload (email, password, TOTP, backup code), exposing sensitive authentication data in logs. Replace it with a sanitized log that omits secrets or remove the log entirely.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

export async function authorizeCredentials(
credentials: Record<"email" | "password" | "totpCode" | "backupCode", string> | undefined
): Promise<User | null> {
log.debug("CredentialsProvider:credentials:authorize", safeStringify({ credentials }));
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 3, 2025

Choose a reason for hiding this comment

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

P1: Rule violated: Avoid Logging Sensitive Information

authorizeCredentials logs the entire credentials payload (email, password, TOTP, backup code), exposing sensitive authentication data in logs. Replace it with a sanitized log that omits secrets or remove the log entirely.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/features/auth/lib/next-auth-options.ts, line 143:

<comment>`authorizeCredentials` logs the entire credentials payload (email, password, TOTP, backup code), exposing sensitive authentication data in logs. Replace it with a sanitized log that omits secrets or remove the log entirely.</comment>

<file context>
@@ -133,139 +133,144 @@ const checkIfUserShouldBelongToOrg = async (idP: IdentityProvider, email: string
+export async function authorizeCredentials(
+  credentials: Record&lt;&quot;email&quot; | &quot;password&quot; | &quot;totpCode&quot; | &quot;backupCode&quot;, string&gt; | undefined
+): Promise&lt;User | null&gt; {
+  log.debug(&quot;CredentialsProvider:credentials:authorize&quot;, safeStringify({ credentials }));
+  if (!credentials) {
+    console.error(`For some reason credentials are missing`);
</file context>
Suggested change
log.debug("CredentialsProvider:credentials:authorize", safeStringify({ credentials }));
log.debug("CredentialsProvider:credentials:authorize", {
hasCredentials: Boolean(credentials),
identifier: credentials?.email ? hashEmail(credentials.email) : undefined,
});
Fix with Cubic

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/features/auth/lib/next-auth-options.ts">

<violation number="1" location="packages/features/auth/lib/next-auth-options.ts:143">
P1: Rule violated: **Avoid Logging Sensitive Information**

`authorizeCredentials` still logs the full `credentials` object, exposing email, password, TOTP, and backup codes in logs, which violates the “Avoid Logging Sensitive Information” rule.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

export async function authorizeCredentials(
credentials: Record<"email" | "password" | "totpCode" | "backupCode", string> | undefined
): Promise<User | null> {
log.debug("CredentialsProvider:credentials:authorize", safeStringify({ credentials }));
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 3, 2025

Choose a reason for hiding this comment

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

P1: Rule violated: Avoid Logging Sensitive Information

authorizeCredentials still logs the full credentials object, exposing email, password, TOTP, and backup codes in logs, which violates the “Avoid Logging Sensitive Information” rule.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/features/auth/lib/next-auth-options.ts, line 143:

<comment>`authorizeCredentials` still logs the full `credentials` object, exposing email, password, TOTP, and backup codes in logs, which violates the “Avoid Logging Sensitive Information” rule.</comment>

<file context>
@@ -133,139 +133,144 @@ const checkIfUserShouldBelongToOrg = async (idP: IdentityProvider, email: string
+export async function authorizeCredentials(
+  credentials: Record&lt;&quot;email&quot; | &quot;password&quot; | &quot;totpCode&quot; | &quot;backupCode&quot;, string&gt; | undefined
+): Promise&lt;User | null&gt; {
+  log.debug(&quot;CredentialsProvider:credentials:authorize&quot;, safeStringify({ credentials }));
+  if (!credentials) {
+    console.error(`For some reason credentials are missing`);
</file context>
Suggested change
log.debug("CredentialsProvider:credentials:authorize", safeStringify({ credentials }));
log.debug("CredentialsProvider:credentials:authorize", safeStringify({ hasCredentials: Boolean(credentials) }));
Fix with Cubic

@github-actions
Copy link
Contributor

This PR has been marked as stale due to inactivity. If you're still working on it or need any help, please let us know or update the PR to keep it active.

@github-actions github-actions bot added the Stale label Dec 11, 2025
Copy link
Contributor

@hbjORbj hbjORbj left a comment

Choose a reason for hiding this comment

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

Nice refactor!

@emrysal emrysal merged commit 68a8fad into main Dec 14, 2025
39 of 42 checks passed
@emrysal emrysal deleted the tests/next-auth-options branch December 14, 2025 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants