Skip to content

Farcaster example flaky #836

Description

@kurtisassad

✅ Prerequisites

  • Did you perform a cursory search of open issues? Is this bug already reported elsewhere?
  • Are you running the latest SDK version?
  • Are you reporting to the correct repository (magic-sdk)?

🐛 Description

In the farcaster docs (https://magic.link/docs/authentication/login/farcaster#example) we have:

import { Magic } from 'magic-sdk';
import { FarcasterExtension } from '@magic-ext/farcaster';

const magic = new Magic('YOUR_API_KEY', {
  extensions: [new FarcasterExtension()],
});

try {
  await magic.farcaster.login();
} catch {
  // Handle errors or reject if required!
}

But note that this sometimes fails if the request doesn't go through before login is called due to the async nature of the constructor:

(@magic-ext/farcaster/src/index.ts)

export class FarcasterExtension
...

constructor() {
    super();

    (async () => {
      this.channel = await fetch(`${FARCASTER_RELAY_URL}/v1/channel`, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          domain: window.location.host,
          siweUri: window.location.origin,
        }),
      }).then<CreateChannelAPIResponse>((r) => r.json());
    })();
  }

public login = (params?: LoginParams) => {
    if (!this.channel) {
      throw new Error('Channel not created yet.');
    }
...

Note that in the case where the request in the constructor does not resolve before login is called, the error Channel not created yet. is thrown.

🧩 Steps to Reproduce

  1. Use the example in the docs
  2. Set network to 3G in browser dev tools

🤔 Expected behavior

Should work correctly and show the farcaster login UI

😮 Actual behavior

An error Channel not created yet. is thrown.

💻 Code Sample

[If possible, please provide a code repository, gist, code snippet or sample files to reproduce the issue.]

🌎 Environment

Software Version(s)
magic-sdk 28.17.0
Browser Chrome 130
pnpm 9.12.3
Operating System macos

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions