Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add farcaster extension #750

Merged
merged 19 commits into from
Jun 20, 2024
Merged

feat: Add farcaster extension #750

merged 19 commits into from
Jun 20, 2024

Conversation

ysm-dev
Copy link
Contributor

@ysm-dev ysm-dev commented Jun 17, 2024

πŸ“¦ Pull Request

[Provide a general summary of the pull request here.]

βœ… Fixed Issues

  • [List any fixed issues here like: Fixes #XXXX]

🚨 Test instructions

[Describe any additional context required to test the PR/feature/bug fix.]

⚠️ Don't forget to add a semver label!

Please 🚨 ONLY ADD ONE 🚨 of the following labels, failing to do so may lead to adverse versioning of your changes when published:

  • patch: Bug Fix?
  • minor: New Feature?
  • major: Breaking Change?
  • skip-release: It's unnecessary to publish this change.

Special Note

Please avoid adding any of the Priority labels as they conflict with the labels above ☝️

πŸ“¦ Published PR as canary version: Canary Versions

✨ Test out this PR locally via:

npm install @magic-ext/[email protected]
# or 
yarn add @magic-ext/[email protected]

@ysm-dev ysm-dev requested review from Ethella and hcote June 17, 2024 16:10
@ysm-dev ysm-dev self-assigned this Jun 17, 2024
@ysm-dev ysm-dev requested a review from octave08 June 17, 2024 16:13
packages/@magic-ext/farcaster/src/index.ts Outdated Show resolved Hide resolved

callback(data as any);

if (!showUI) return;
Copy link
Member

@Ethella Ethella Jun 17, 2024

Choose a reason for hiding this comment

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

If showUI is false, will login the happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, under this if statement is just for show QRCode in mandrake,
if showUI is false, we don't show our QRCode popup, developer should display their QRCode design.

Copy link
Member

Choose a reason for hiding this comment

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

A follow-up question, How would the developer know it's time to show the QRCode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

QRCode shows when dev calls magic.farcaster.login({ showUI: true })
So dev can add this function on Sign in with Farcaster Button onClick

const handle = {
on: <T extends EventName>(event: T, callback: (params: EventMap[T]) => void) => {
if (event === EVENT.CHANNEL) {
!(async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need an exclamation mark here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -146,6 +146,10 @@ export enum AuthEventOnReceived {
IDTokenCreated = 'Auth/id-token-created',
}

export enum FarcasterLoginEventEmit {
SuccessSignIn = 'success_sign_in',
Copy link
Member

Choose a reason for hiding this comment

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

Could we turn this to farcaster/success_sign_in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ysm-dev ysm-dev requested a review from Ethella June 17, 2024 17:59
@ysm-dev ysm-dev changed the base branch from master to chris/farcaster-types June 18, 2024 09:18
Base automatically changed from chris/farcaster-types to master June 18, 2024 09:28
@hcote
Copy link
Contributor

hcote commented Jun 18, 2024

Is there a reason this logic can't be in the iframe? I think it's more maintainable that way where the sdk just sends an rpc method magic_auth_farcaster_login then the iframe handles the rest, then you don't have to pass events between the sdk and iframe.

callback(data as any);
channel_token = data.channelToken;

if (isMobile()) {
Copy link
Member

Choose a reason for hiding this comment

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

I noticed a potential issue when the user is on a mobile device. The showUI condition won't have any effect in that case. If that's by design, I'd suggest putting a console warning or info to explain this. Otherwise, people might ask why the flag is not working.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it's by design, we don't display QR on mobile device, and just open channel URL.
I will add console info

@@ -9,7 +9,7 @@ async function main() {
const PKG = await promptForPackage();

printSeparator('Linting TypeScripts');
await execa('yarn', ['wsrun', '--serial', 'eslint', '--fix', '.'], {
await execa('yarn', ['wsrun', '--serial', 'eslint', '--fix'], {
Copy link
Member

@Ethella Ethella Jun 18, 2024

Choose a reason for hiding this comment

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

Does this skip the linter stage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to fix below typescript-eslint issue (explained below)

@@ -69,7 +70,7 @@
"ts-node": "^10.2.0",
"tsc-watch": "^4.2.9",
"tslib": "^2.3.1",
"typescript": "~4.4.2",
"typescript": "^5.4.5",
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest not to bump the typescript version, as it might break other implementations. We'll need a thorough code scan once we bump the version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I bumped because @farcaster/auth-client library dependent to viem
and viem has peerDependency to TypeScript >5.0.4 https://github.com/wevm/viem/blob/main/src/package.json#L117
So it breaks CI when I installed viem in @magic-ext/farcaster

@ysm-dev ysm-dev requested a review from Ethella June 19, 2024 06:02
@ysm-dev
Copy link
Contributor Author

ysm-dev commented Jun 20, 2024

Is there a reason this logic can't be in the iframe? I think it's more maintainable that way where the sdk just sends an rpc method magic_auth_farcaster_login then the iframe handles the rest, then you don't have to pass events between the sdk and iframe.

@hcote

When I initially designed the implementation, I thought that in the case where the user set showUI to false, there is no UI to show on the mandrake side at all, so it could only be handled in magic-js.

And to get both socket channel open event and success event from handler to farcaster login relayer, I thought it was similar because I need to send events from mandrake side to iframe side anyway.

@hcote
Copy link
Contributor

hcote commented Jun 20, 2024

We can handle this still in mandrake when there's no UI shown (this is how we handle ui-less requests like getInfo.

I think it'd be a lot simpler to maintain to have the logic in mandrake, and future updates would not require new sdk versions, but if there's a good reason why it needs to be in magic-js I'm open to doing it in here

@Ethella
Copy link
Member

Ethella commented Jun 20, 2024

We can handle this still in mandrake when there's no UI shown (this is how we handle ui-less requests like getInfo.

I think it'd be a lot simpler to maintain to have the logic in mandrake, and future updates would not require new sdk versions, but if there's a good reason why it needs to be in magic-js I'm open to doing it in here

I believe the reason is that Farcaster, as a type of social login, may block authentication requests submitted from iframes or webviews in the future as a security measure, similar to Google OAuth.

channel_token = data.channelToken;

if (isMobile()) {
console.info(`Info: showUI parameter is ignored on mobile, open URL directly`);
Copy link
Contributor

Choose a reason for hiding this comment

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

This console.info should be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this from @Ethella 's review: #750 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Could you change the message to Magic -> farcaster extension: showUI parameter is ignored on mobile, open URL directly

@hcote
Copy link
Contributor

hcote commented Jun 20, 2024

@ysm-dev The deepsource errors are from the uses of any - they should be replaced with non-any types

@Ethella
Copy link
Member

Ethella commented Jun 20, 2024

Created @magic-ext/farcaster package for CI publishing

@Ethella
Copy link
Member

Ethella commented Jun 20, 2024

Please address the deepsource, otherwise LGTM

@ysm-dev
Copy link
Contributor Author

ysm-dev commented Jun 20, 2024

@Ethella @hcote fixed!

@ysm-dev ysm-dev requested a review from hcote June 20, 2024 17:13
@ysm-dev ysm-dev added this pull request to the merge queue Jun 20, 2024
Merged via the queue into master with commit 99863af Jun 20, 2024
6 checks passed
@ysm-dev ysm-dev deleted the chris/farcaster-1 branch June 20, 2024 18:36
@svc-magic-git
Copy link

πŸš€ PR was released in @magic-ext/[email protected] πŸš€

@svc-magic-git svc-magic-git added the released This issue/pull request has been released. label Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants