Skip to content

fix: replace direct console.* calls with authLogger in auth package#1593

Open
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1771608565-auth-use-sdk-logger
Open

fix: replace direct console.* calls with authLogger in auth package#1593
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1771608565-auth-use-sdk-logger

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Feb 20, 2026

Description

Part of the effort to make consoleLogLevel="silent" suppress logs across all SDK packages. Replaces 4 direct console.* calls in CrossmintAuthClient with a new package-level authLogger instance, properly initialized via initAuthLogger(apiKey).

Changes:

  • New src/logger.ts — creates authLogger singleton and initAuthLogger(apiKey) initializer (validates API key, inits logger with package name/environment/projectId, adds platform-appropriate Datadog sink)
  • CrossmintAuthClient.from() — calls initAuthLogger(crossmint.apiKey) before constructing the client
  • CrossmintAuthClient.ts — 4 direct console.* calls → authLogger.debug / authLogger.error
  • CrossmintAuthClient.test.ts — updated to spy on authLogger.error instead of console.error

Note: initAuthLogger uses optional chaining (validationResult?.isValid) as a defensive guard — when tests mock @crossmint/common-sdk-base, validateAPIKey returns undefined, so this prevents TypeError without requiring test changes.

Requested by: @xmint-guille
Link to Devin run

Items for reviewer attention

  1. No consoleLogLevel parameter on initAuthLogger — unlike initReactLogger, this init function doesn't accept a consoleLogLevel param. The SdkLogger shared sinkManager should propagate the level set by CrossmintProvider, but worth verifying.
  2. No double-init guardinitAuthLogger is called on every CrossmintAuthClient.from() invocation. Verify SdkLogger.init() handles repeated calls gracefully.

Test plan

  • Existing test updated to spy on authLogger.error instead of console.error
  • All 30 tests in CrossmintAuthClient.test.ts pass locally after the defensive optional chaining fix
  • Lint passes (pnpm lint)

Package updates

  • @crossmint/client-sdk-auth: patch (changeset added)

@devin-ai-integration
Copy link
Contributor Author

Original prompt from Guille
we introduced the following change here to supress logs in our sdks:
https://github.com/Crossmint/crossmint-sdk/commit/27194e5751fd4bb3afb190550382760f978d7a20

i've tried this with the following code snippet, and I can still see logs once I'm logged in:
```ts
"use client";

import {
  CrossmintProvider,
  CrossmintAuthProvider,
  CrossmintWalletProvider,
  useAuth,
  useWallet,
} from "@crossmint/client-sdk-react-ui";

function WalletUser() {
  const { login, user } = useAuth();
  const { wallet, status } = useWallet();

  return (
    <div>
      {user == null ? (
        <button onClick={login}>Sign In</button>
      ) : (
        <p>
          Wallet: {wallet?.address} ({status})
        </p>
      )}
    </div>
  );
}

export default function Page() {
  return (
    <CrossmintProvider
      apiKey={process.env.NEXT_PUBLIC_CLIENT_API_KEY ?? ""}
      consoleLogLevel="silent"
    >
      <CrossmintAuthProvider>
        <CrossmintWalletProvider
          createOnLogin={{
            chain: "polygon-amoy",
            signer: { type: "email" },
          }}
        >
          <WalletUser />
        </CrossmintWalletProvider>
      </CrossmintAuthProvider>
    </CrossmintProvider>
  );
}

can you determine the issue and propose a PR in case it's feasible to maintain the silent logs flag in every part of our sdks?

</details>

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2026

🦋 Changeset detected

Latest commit: dee1ea4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@crossmint/client-sdk-auth Patch
@crossmint/client-sdk-react-base Patch
@crossmint/client-sdk-react-native-ui Patch
@crossmint/client-sdk-react-ui Patch
expo-demo Patch
@crossmint/auth-ssr-nextjs-demo Patch
@crossmint/client-sdk-nextjs-starter Patch
@crossmint/wallets-quickstart-devkit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +11 to +21
export function initAuthLogger(apiKey: string): void {
const validationResult = validateAPIKey(apiKey);
if (!validationResult.isValid) {
return;
}
const { environment, projectId } = validationResult;
authLogger.init({
packageName: "@crossmint/client-sdk-auth",
environment,
projectId,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider accepting consoleLogLevel parameter to enable users to suppress console output (similar to initReactLogger). Currently, users cannot configure silent mode for auth logs even though the underlying SdkLogger supports it.

Suggested change
export function initAuthLogger(apiKey: string): void {
const validationResult = validateAPIKey(apiKey);
if (!validationResult.isValid) {
return;
}
const { environment, projectId } = validationResult;
authLogger.init({
packageName: "@crossmint/client-sdk-auth",
environment,
projectId,
});
export function initAuthLogger(apiKey: string, consoleLogLevel?: ConsoleLogLevel): void {
const validationResult = validateAPIKey(apiKey);
if (!validationResult.isValid) {
return;
}
const { environment, projectId } = validationResult;
authLogger.init({
packageName: "@crossmint/client-sdk-auth",
environment,
projectId,
consoleLogLevel,
});

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/auth/src/logger.ts
Line: 11-21

Comment:
Consider accepting `consoleLogLevel` parameter to enable users to suppress console output (similar to `initReactLogger`). Currently, users cannot configure silent mode for auth logs even though the underlying `SdkLogger` supports it.

```suggestion
export function initAuthLogger(apiKey: string, consoleLogLevel?: ConsoleLogLevel): void {
    const validationResult = validateAPIKey(apiKey);
    if (!validationResult.isValid) {
        return;
    }
    const { environment, projectId } = validationResult;
    authLogger.init({
        packageName: "@crossmint/client-sdk-auth",
        environment,
        projectId,
        consoleLogLevel,
    });
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +17 to +21
authLogger.init({
packageName: "@crossmint/client-sdk-auth",
environment,
projectId,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

consoleLogLevel is not being passed to authLogger.init(), which means users cannot suppress auth logs even when setting consoleLogLevel="silent". The logger will always use the default "debug" level for console output.

Suggested change
authLogger.init({
packageName: "@crossmint/client-sdk-auth",
environment,
projectId,
});
authLogger.init({
packageName: "@crossmint/client-sdk-auth",
environment,
projectId,
consoleLogLevel,
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/auth/src/logger.ts
Line: 17-21

Comment:
`consoleLogLevel` is not being passed to `authLogger.init()`, which means users cannot suppress auth logs even when setting `consoleLogLevel="silent"`. The logger will always use the default "debug" level for console output.

```suggestion
    authLogger.init({
        packageName: "@crossmint/client-sdk-auth",
        environment,
        projectId,
        consoleLogLevel,
    });
```

How can I resolve this? If you propose a fix, please make it concise.


export const authLogger = new SdkLogger();

export function initAuthLogger(apiKey: string): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

initAuthLogger() needs to accept a consoleLogLevel parameter (similar to initReactLogger() in packages/client/react-base/src/logger/init.ts:19) so users can control console output verbosity.

Suggested change
export function initAuthLogger(apiKey: string): void {
export function initAuthLogger(apiKey: string, consoleLogLevel?: ConsoleLogLevel): void {
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/auth/src/logger.ts
Line: 11

Comment:
`initAuthLogger()` needs to accept a `consoleLogLevel` parameter (similar to `initReactLogger()` in packages/client/react-base/src/logger/init.ts:19) so users can control console output verbosity.

```suggestion
export function initAuthLogger(apiKey: string, consoleLogLevel?: ConsoleLogLevel): void {
```

How can I resolve this? If you propose a fix, please make it concise.

}

public static from(crossmint: Crossmint, config: CrossmintAuthClientConfig = {}): CrossmintAuthClient {
initAuthLogger(crossmint.apiKey);
Copy link
Contributor

Choose a reason for hiding this comment

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

consoleLogLevel needs to be passed to initAuthLogger(). First, add consoleLogLevel to CrossmintAuthClientConfig type (similar to how CrossmintProviderProps extends CrossmintConfig in packages/client/ui/react-ui/src/providers/CrossmintProvider.tsx:12), then pass it here.

Suggested change
initAuthLogger(crossmint.apiKey);
initAuthLogger(crossmint.apiKey, config.consoleLogLevel);
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/auth/src/CrossmintAuthClient.ts
Line: 43

Comment:
`consoleLogLevel` needs to be passed to `initAuthLogger()`. First, add `consoleLogLevel` to `CrossmintAuthClientConfig` type (similar to how `CrossmintProviderProps` extends `CrossmintConfig` in packages/client/ui/react-ui/src/providers/CrossmintProvider.tsx:12), then pass it here.

```suggestion
        initAuthLogger(crossmint.apiKey, config.consoleLogLevel);
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +1 to +7
import {
SdkLogger,
validateAPIKey,
detectPlatform,
BrowserDatadogSink,
ServerDatadogSink,
} from "@crossmint/common-sdk-base";
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing ConsoleLogLevel import needed for the function signature.

Suggested change
import {
SdkLogger,
validateAPIKey,
detectPlatform,
BrowserDatadogSink,
ServerDatadogSink,
} from "@crossmint/common-sdk-base";
import {
SdkLogger,
validateAPIKey,
detectPlatform,
BrowserDatadogSink,
ServerDatadogSink,
type ConsoleLogLevel,
} from "@crossmint/common-sdk-base";
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/auth/src/logger.ts
Line: 1-7

Comment:
Missing `ConsoleLogLevel` import needed for the function signature.

```suggestion
import {
    SdkLogger,
    validateAPIKey,
    detectPlatform,
    BrowserDatadogSink,
    ServerDatadogSink,
    type ConsoleLogLevel,
} from "@crossmint/common-sdk-base";
```

How can I resolve this? If you propose a fix, please make it concise.

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