-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(web): Hubspot onboarding invite member flow #5674
Changes from 6 commits
7d7ba3f
a958e34
318612f
e5d8209
e141bb8
205caf5
77631f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,16 @@ export interface LocationState { | |
|
||
export function LoginForm({ email, invitationToken }: LoginFormProps) { | ||
const segment = useSegment(); | ||
const { login, currentUser, organizationId, environmentId } = useAuth(); | ||
const { login, currentUser, organizations } = useAuth(); | ||
const { startVercelSetup } = useVercelIntegration(); | ||
const { isFromVercel, params: vercelParams } = useVercelParams(); | ||
const [params] = useSearchParams(); | ||
const tokenInQuery = params.get('token'); | ||
const source = params.get('source'); | ||
const sourceWidget = params.get('source_widget'); | ||
const invitationTokenFromGithub = params.get('invitationToken') as string; | ||
const isRedirectedFromLoginPage = params.get('isLoginPage') as string; | ||
|
||
const { isLoading: isLoadingAcceptInvite, acceptInvite } = useAcceptInvite(); | ||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
|
@@ -48,40 +51,59 @@ export function LoginForm({ email, invitationToken }: LoginFormProps) { | |
} | ||
>((data) => api.post('/v1/auth/login', data)); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
if (!tokenInQuery) { | ||
return; | ||
} | ||
const handleLoginInUseEffect = async () => { | ||
// if currentUser is true, it means user exists, then while accepting invitation, InvitationPage will handle accept this case | ||
if (currentUser) { | ||
return; | ||
} | ||
|
||
if (!invitationToken && (!organizationId || !environmentId)) { | ||
await login(tokenInQuery, ROUTES.AUTH_APPLICATION); | ||
// if token from github is not present | ||
jainpawan21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!tokenInQuery) { | ||
return; | ||
} | ||
|
||
return; | ||
} | ||
// handle github login after invitation | ||
if (invitationTokenFromGithub) { | ||
await login(tokenInQuery); | ||
const updatedToken = await acceptInvite(invitationTokenFromGithub); | ||
|
||
if (isFromVercel) { | ||
await login(tokenInQuery); | ||
startVercelSetup(); | ||
if (updatedToken) { | ||
await login(updatedToken, isRedirectedFromLoginPage === 'true' ? ROUTES.WORKFLOWS : ROUTES.AUTH_APPLICATION); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ouch. This has to be done this way as the accept invitation endpoint is authenticated but it shouldn't. Removing the What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, the user should exist before accepting invitation. So current |
||
|
||
return; | ||
} | ||
} | ||
|
||
if (source === 'cli') { | ||
segment.track('Dashboard Visit', { | ||
widget: sourceWidget || 'unknown', | ||
source: 'cli', | ||
}); | ||
await login(tokenInQuery, ROUTES.GET_STARTED); | ||
|
||
return; | ||
} | ||
if (organizations) { | ||
navigate(ROUTES.WORKFLOWS); | ||
} else { | ||
await login(tokenInQuery, ROUTES.AUTH_APPLICATION); | ||
} | ||
|
||
if (isFromVercel) { | ||
await login(tokenInQuery); | ||
navigate(ROUTES.WORKFLOWS); | ||
})(); | ||
startVercelSetup(); | ||
|
||
return; | ||
} | ||
|
||
if (source === 'cli') { | ||
segment.track('Dashboard Visit', { | ||
widget: sourceWidget || 'unknown', | ||
source: 'cli', | ||
}); | ||
await login(tokenInQuery, ROUTES.GET_STARTED); | ||
|
||
return; | ||
} | ||
|
||
await login(tokenInQuery, ROUTES.WORKFLOWS); | ||
}; | ||
|
||
useEffect(() => { | ||
handleLoginInUseEffect(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [login, navigate, currentUser, tokenInQuery, segment, organizationId, environmentId]); | ||
}, [login]); | ||
|
||
const signupLink = isFromVercel ? `${ROUTES.AUTH_SIGNUP}?${params.toString()}` : ROUTES.AUTH_SIGNUP; | ||
const resetPasswordLink = isFromVercel | ||
|
@@ -135,7 +157,7 @@ export function LoginForm({ email, invitationToken }: LoginFormProps) { | |
|
||
return ( | ||
<> | ||
<OAuth /> | ||
<OAuth invitationToken={invitationToken} isLoginPage={true} /> | ||
<form noValidate onSubmit={handleSubmit(onLogin)}> | ||
<Input | ||
error={emailClientError || emailServerError} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,21 @@ import { SignUpOriginEnum } from '@novu/shared'; | |
|
||
import { API_ROOT } from '../../../config'; | ||
|
||
export const buildGithubLink = ({ invitationToken }: { invitationToken?: string }) => { | ||
export const buildGithubLink = ({ | ||
invitationToken, | ||
isLoginPage, | ||
}: { | ||
invitationToken?: string; | ||
isLoginPage?: boolean; | ||
}) => { | ||
const queryParams = new URLSearchParams(); | ||
queryParams.append('source', SignUpOriginEnum.WEB); | ||
if (invitationToken) { | ||
queryParams.append('invitationToken', invitationToken); | ||
} | ||
if (isLoginPage) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto about |
||
queryParams.append('isLoginPage', 'true'); | ||
} | ||
|
||
return `${API_ROOT}/v1/auth/github?${queryParams.toString()}`; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,10 @@ export const buildOauthRedirectUrl = (request): string => { | |
if (invitationToken) { | ||
url += `&invitationToken=${invitationToken}`; | ||
} | ||
const isLoginPage = JSON.parse(request.query.state).isLoginPage; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of marking whether OAuth comes from loginPage, we can add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SokratisVidros which means instead of hardcoed |
||
if (isLoginPage) { | ||
url += `&isLoginPage=${isLoginPage}`; | ||
} | ||
|
||
return url; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indicates a routing issue as the invitation handling should be done in one place, not between pages. It's OK for now but we will have to get back to this.