Skip to content

Farcaster example flakyย #836

@kurtisassad

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

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