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

[NAN-578] Implement Google Social Login/Signup #1872

Merged
merged 17 commits into from Mar 20, 2024

Conversation

khaliqgant
Copy link
Member

@khaliqgant khaliqgant commented Mar 18, 2024

Describe your changes

Adds in google auth using workos

image

Issue ticket number and link

NAN-578

Checklist before requesting a review (skip if just adding/editing APIs & templates)

  • I added tests, otherwise the reason is:
  • I added observability, otherwise the reason is:
  • I added analytics, otherwise the reason is:

Copy link

linear bot commented Mar 18, 2024

packages/server/lib/server.ts Dismissed Show dismissed Hide dismissed
@khaliqgant khaliqgant changed the title Khaliq/nan 578 implement social auth google [NAN-578] Implement Google Social Login/Signup Mar 19, 2024
@khaliqgant khaliqgant marked this pull request as ready for review March 19, 2024 12:57
Copy link
Contributor

@bodinsamuel bodinsamuel left a comment

Choose a reason for hiding this comment

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

Tested in staging, works well 💪🏻

packages/server/lib/controllers/auth.controller.ts Outdated Show resolved Hide resolved
packages/server/lib/controllers/auth.controller.ts Outdated Show resolved Hide resolved
packages/webapp/src/pages/InviteSignup.tsx Outdated Show resolved Hide resolved
@@ -0,0 +1,82 @@
interface Props {
Copy link
Contributor

Choose a reason for hiding this comment

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

I was the impression that /ui folder was for Generic reusable component, this one is really a one of. (my pov is that everything is related to ui anyway so it's either an unnecessary hierarchy level or it's specific for one scenario)

packages/server/lib/controllers/auth.controller.ts Outdated Show resolved Hide resolved
packages/webapp/src/pages/ResetPassword.tsx Outdated Show resolved Hide resolved
@khaliqgant
Copy link
Member Author

@bodinsamuel Thanks for the review. I updated the PR based on some of your feedback. The other items I didn't see as blocking but let me know if you feel strongly about any items I didn't address and I can add more color on why I didn't adjust it based on your feedback.

packages/server/lib/controllers/auth.controller.ts Outdated Show resolved Hide resolved
}

const createAccountIfNotInvited = async (state: string, name: string): Promise<number | null> => {
const parsedAccount = (state ? JSON.parse(Buffer.from(state, 'base64').toString('ascii')) : null) as InviteAccountState | null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cannot JSON.parse throw an exception? What should happen in this case?

}

return accountId;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

can this be?

    const res: Result<InviteAccountState> = parseState(state) // returns a valid InviteAccountState or a ResultErr
    if (isOk(res)) {
        const validToken = await userService.getInvitedUserByToken(token);
        if (validToken) {
            await userService.markAcceptedInvite(parsedAccount.token);
        }
        return parsedAccount.accountId ;
    }

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, updated

if (!workos) {
errorManager.errRes(res, 'workos_not_configured');
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

see my comment above. This is not a concern for the user and I think it would be better to crash the server at startup

Copy link
Member Author

Choose a reason for hiding this comment

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

WorkOS is only required for Cloud so don't think it should crash here.

Copy link
Collaborator

@TBonnin TBonnin Mar 20, 2024

Choose a reason for hiding this comment

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

what I mean is this is a configuration issue that would better detected as soon as possible (aka: when the app starts) rather than deferred to whenever a request is being received.
For sure for non-cloud setup this configuration can be ignored.

I prefer never to deployed a misconfigured app than getting a bug report by an end-user

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, I gotcha, but who are we protecting here? Developers running the application locally? Cloud will have the necessary env variables.

Copy link
Collaborator

@TBonnin TBonnin Mar 20, 2024

Choose a reason for hiding this comment

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

Yup, I gotcha, but who are we protecting here?

We protecting our future self

Cloud will have the necessary env variables.

They will, until one day the infra changes and configuration is somehow forgotten or messed up.
In general trying to detect error as soon as possible is a good principle to follow.

Not a blocker though.

? `${authorizedUser.firstName || ''} ${authorizedUser.lastName || ''}`
: authorizedUser.email.split('@')[0];

const accountId = await createAccountIfNotInvited(state as string, name as string);
Copy link
Collaborator

Choose a reason for hiding this comment

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

should state and name be validated prior to make sure they are acceptable string. That would also avoid having to cast them

@@ -260,6 +292,79 @@ class AuthController {
next(error);
}
}

getHostedLogin(req: Request, res: Response, next: NextFunction) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure what Hosted referred to here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hosted = WorkOs

Copy link
Contributor

Choose a reason for hiding this comment

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

I find our use of Hosted rather confusing, everything is hosted by default.
Is it enterprise, cloud or community? if hosted = enterprise + cloud maybe we can come up with a naming more representative like "managed".
Plus we use hosted for self-hosted in the Docker images right now, which is the opposite

Copy link
Contributor

@bodinsamuel bodinsamuel left a comment

Choose a reason for hiding this comment

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

Minor comments 👌🏻

packages/webapp/src/components/ui/button/Auth/Google.tsx Outdated Show resolved Hide resolved
@@ -260,6 +292,79 @@ class AuthController {
next(error);
}
}

getHostedLogin(req: Request, res: Response, next: NextFunction) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I find our use of Hosted rather confusing, everything is hosted by default.
Is it enterprise, cloud or community? if hosted = enterprise + cloud maybe we can come up with a naming more representative like "managed".
Plus we use hosted for self-hosted in the Docker images right now, which is the opposite

packages/server/lib/server.ts Outdated Show resolved Hide resolved
@khaliqgant
Copy link
Member Author

I add the impression that user could only be part of one org, so if they only have one, they get suspended and they login what are they seeing?

If a user is suspended they're essentially locked out of Nango. Handling this seems out of scope of this as it is a known limitation of the invite flow. Let me know if you disagree

Copy link
Collaborator

@TBonnin TBonnin left a comment

Choose a reason for hiding this comment

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

I have only one small feedback regarding configuration management but other than that looks good.

Copy link
Contributor

@bodinsamuel bodinsamuel left a comment

Choose a reason for hiding this comment

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

Minor comments still opened but overall ✅

@bodinsamuel
Copy link
Contributor

Tested one last time on staging, all good 👍🏻

@khaliqgant khaliqgant merged commit 59d64f2 into master Mar 20, 2024
18 checks passed
@khaliqgant khaliqgant deleted the khaliq/nan-578-implement-social-auth-google branch March 20, 2024 18:06
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.

None yet

3 participants