-
Notifications
You must be signed in to change notification settings - Fork 128
Open
Description
โ 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
- Use the example in the docs
- 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 |