Skip to content

Commit

Permalink
fix(web): add redirect to page after login (novuhq#5668)
Browse files Browse the repository at this point in the history
* fix: add redirect to team page after login

* fix: changed to _organization

* refactor(invite-nudge): simplify logger message string

* refactor(auth): make redirectTo pathname optional

---------

Co-authored-by: Richard Fontein <[email protected]>
  • Loading branch information
jainpawan21 and rifont authored Jun 5, 2024
1 parent 2f4290e commit 5c4391b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Scope } from '@nestjs/common';
import { Injectable, Scope, Logger } from '@nestjs/common';
import { MemberRepository } from '@novu/dal';
import { GetFeatureFlag, GetFeatureFlagCommand, createHash } from '@novu/application-generic';
import { FeatureFlagsKeysEnum } from '@novu/shared';
Expand Down Expand Up @@ -37,7 +37,7 @@ export class InviteNudgeWebhook {
});

if (membersCount === 1) {
await axiosInstance.post(
const hubspotAddUserIntoListResponse = await axiosInstance.post(
`https://api.hubapi.com/contacts/v1/lists/${process.env.HUBSPOT_INVITE_NUDGE_EMAIL_USER_LIST_ID}/add`,
{
emails: [command.subscriber.email],
Expand All @@ -48,6 +48,11 @@ export class InviteNudgeWebhook {
},
}
);
if (hubspotAddUserIntoListResponse.data.updated.length !== 1) {
Logger.log(
`Failed to add user ${command.subscriber.email} into list ${process.env.HUBSPOT_INVITE_NUDGE_EMAIL_USER_LIST_ID}`
);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions apps/api/src/app/widgets/widgets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ export class WidgetsController {
): Promise<LogUsageResponseDto> {
this.analyticsService.track(body.name, subscriberSession._organizationId, {
environmentId: subscriberSession._environmentId,
_organization: subscriberSession._organizationId,
...(body.payload || {}),
});

Expand Down
7 changes: 4 additions & 3 deletions apps/web/src/pages/auth/components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type LoginFormProps = {
};

export interface LocationState {
redirectTo: {
pathname: string;
redirectTo?: {
pathname?: string;
};
}

Expand All @@ -38,6 +38,7 @@ export function LoginForm({ email, invitationToken }: LoginFormProps) {
const { isLoading: isLoadingAcceptInvite, acceptInvite } = useAcceptInvite();
const navigate = useNavigate();
const location = useLocation();
const state = location.state as LocationState;
const { isLoading, mutateAsync, isError, error } = useMutation<
{ token: string },
IResponseError,
Expand Down Expand Up @@ -116,7 +117,7 @@ export function LoginForm({ email, invitationToken }: LoginFormProps) {
}
}

navigate(ROUTES.WORKFLOWS);
navigate(state?.redirectTo?.pathname || ROUTES.WORKFLOWS);
} catch (e: any) {
if (e.statusCode !== 400) {
Sentry.captureException(e);
Expand Down
2 changes: 1 addition & 1 deletion libs/shared-web/src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function useAuth() {

useEffect(() => {
if (!getToken() && inPrivateRoute) {
navigate(ROUTES.AUTH_LOGIN);
navigate(ROUTES.AUTH_LOGIN, { state: { redirectTo: location } });
}
}, [navigate, inPrivateRoute]);

Expand Down

0 comments on commit 5c4391b

Please sign in to comment.