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

MagicV2 + Farcaster login + SMS login #9913

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

MagicV2 + Farcaster login + SMS login #9913

wants to merge 12 commits into from

Conversation

kurtisassad
Copy link
Contributor

@kurtisassad kurtisassad commented Nov 14, 2024

Link to Issue

Closes: #8713
Closes: #9028

Description of Changes

  • Upgrades magic to v2
  • Adds farcaster sign in
  • Adds SMS sign in

Note that the SSO v2 will not be able to work for custom domains. As a result I added extra logic to get the v2 to work for our domain only.

Test Plan

  • For farcaster sign in, Click on sign in button, then under email or social, you will see farcaster:
image
  • For SMS sign in, Click on sign in button, then under email or social, you will see farcaster:
image

After logging in with it, it should prompt you to create an account

  • For v2 testing, check SSO and email logins.

@@ -18,6 +21,12 @@ import { Mava } from './views/components/Mava';

OpenFeature.setProvider(openFeatureProvider);

// need to instantiate it early because the farcaster sdk has an async constructor which will cause a race condition
// if instantiated right before the login is called;
export const defaultMagic = new Magic(process.env.MAGIC_PUBLISHABLE_KEY!, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might not be the best place to put it, but it needs to be instantiated when the app starts. Any better suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure but does this cause circular dependency issues? or maybe we could add to packages/commonwealth/client/scripts/controllers/app/login.ts (that needs it - also login.ts is imported in many init flow conditions)?

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 I moved it to login.ts. And yes this is the cause of the test failure issue. Not exactly a circular dependency but more of this Magic constructor calls the DOM, but our tests don't have the DOM so it throws an error.

But basically this is needed because their constructor needs to complete an async request before we can call login. So basically the earlier it is instantiated the better, but still no guarantee that login won't fail when it is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes to this file were necessary to fix:
https://github.com/hicommonwealth/commonwealth/actions/runs/11843912133/job/33005933192?pr=9913

The issue was that login.ts now relies on the root entrypoint, causing some dependency issue. By passing in the app to these helpers instead of calling it directly, fixes this issue

Comment on lines +339 to +346
} else if (provider === WalletSsoSource.Farcaster) {
const bearer = await magic.farcaster.login();

const { address } = await handleSocialLoginCallback({
bearer,
walletSsoSource: WalletSsoSource.Farcaster,
});

Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to strictly follow this? can we reuse the else block logic below? That would redirect to /finish_social_login and then handleSocialLoginCallback is already called there along with some app init settings as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a little bit confusing but farcaster is not technically a social login. This is social logins require to use the webhook callback which farcaster does not use since it is decentralized. There is no entity (Like google or whatever) to submit the callback webhook for us.

This basically takes the same path as email login, the only difference is that it needs to call the magic farcaster login method

@@ -116,7 +117,7 @@ export const ThreadCard = ({
const linkedSnapshots = filterLinks(thread.links, LinkSource.Snapshot);
const linkedProposals = filterLinks(thread.links, LinkSource.Proposal);

const isStageDefault = isDefaultStage(thread.stage, customStages);
const isStageDefault = isDefaultStage(app, thread.stage, customStages);
Copy link
Contributor

Choose a reason for hiding this comment

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

this might not work as expected in cases when thread card is used outside communities scope as app?.chain?.meta?.custom_stages would be undefined.

We can instead pass the customStages props to thread card, its already handled for non-community scope cases. For the remaining you'd need to pass customStages={app?.chain?.meta?.custom_stages} to thread card instances in community scope pages and then passing the whole app obj can 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.

This is the exact same logic as we had it previously so it will not break anything that was not already broken. The only difference here is that we pass it in the from the ThreadCard instead of importing it and using it in the helper file.

This is only needed for tests to pass due to some test login referencing this helper file and not having the DOM.

@@ -174,16 +178,16 @@ export function renderMultilineText(text: string) {
* blocknum helpers
*/

export function blocknumToTime(blocknum: number): moment.Moment {
export function blocknumToTime(app: IApp, blocknum: number): moment.Moment {
Copy link
Contributor

Choose a reason for hiding this comment

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

lets just only pass the props it needs -> block: IBlockInfo. We are trying to minimize and completely remove the app object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, fixed.

@mzparacha
Copy link
Contributor

mzparacha commented Nov 15, 2024

Don't have a farcaster account so will need to setup one to test. Will try to setup one and test.

Copy link
Contributor

@masvelio masvelio left a comment

Choose a reason for hiding this comment

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

  1. The confirmation window looks with broken styles. Not sure if we have control about it but used to work well.
image
  1. Not sure if this is part of this PR but getting 400s on searchUserProfile query on onboarding modal.
image
  1. So farcaster flow worked fine for me both on signup and signin. However google, discord, twitter didn;t work for me
image image image

@kurtisassad kurtisassad changed the title MagicV2 + Farcaster login MagicV2 + Farcaster login + SMS login Nov 20, 2024
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.

🪣 Magic Link v2 Upgrade Add Farcaster Login Via Magic
3 participants