diff --git a/apps/console/src/pages/iam/auth/ActivateAccountPage.tsx b/apps/console/src/pages/iam/auth/ActivateAccountPage.tsx index a2217db75..243c5ce6d 100644 --- a/apps/console/src/pages/iam/auth/ActivateAccountPage.tsx +++ b/apps/console/src/pages/iam/auth/ActivateAccountPage.tsx @@ -42,11 +42,13 @@ export default function ActivateAccountPage() { onCompleted: (response: ActivateAccountPageMutation$data, errors: GraphQLError[] | null) => { if (errors) { for (const err of errors) { - if (err.extensions?.code === "ALREADY_AUTHENTICATED") { - window.location.href = "/"; + if (err.extensions?.code === "ACCOUNT_ALREADY_ACTIVATED") { + void navigate({ + pathname: safeContinueUrl.pathname, + search: safeContinueUrl.search, + }, { replace: true }); return; } - // FIXME: If already activated redirect too } toast({ title: __("Activation failed"), diff --git a/pkg/server/api/connect/v1/v1_resolver.go b/pkg/server/api/connect/v1/v1_resolver.go index c91d1323f..c5502ac82 100644 --- a/pkg/server/api/connect/v1/v1_resolver.go +++ b/pkg/server/api/connect/v1/v1_resolver.go @@ -379,14 +379,12 @@ func (r *mutationResolver) ActivateAccount(ctx context.Context, input types.Acti ) if err != nil { var ( - errInvalidToken *iam.ErrInvalidToken - errInvitationNotFound *iam.ErrInvitationNotFound - errInvitationAlreadyAccepted *iam.ErrInvitationAlreadyAccepted - errInvitationExpired *iam.ErrInvitationExpired + errInvalidToken *iam.ErrInvalidToken + errInvitationNotFound *iam.ErrInvitationNotFound + errInvitationExpired *iam.ErrInvitationExpired isInvalidErr = errors.As(err, &errInvalidToken) || errors.As(err, &errInvitationNotFound) || - errors.As(err, &errInvitationAlreadyAccepted) || errors.As(err, &errInvitationExpired) ) @@ -394,6 +392,10 @@ func (r *mutationResolver) ActivateAccount(ctx context.Context, input types.Acti return nil, gqlutils.Invalid(ctx, err) } + if _, ok := errors.AsType[*iam.ErrInvitationAlreadyAccepted](err); ok { + return nil, gqlutils.AccountAlreadyActivated(ctx, err) + } + r.logger.ErrorCtx(ctx, "cannot activate account from invitation", log.Error(err)) return nil, gqlutils.Internal(ctx) } diff --git a/pkg/server/gqlutils/errors.go b/pkg/server/gqlutils/errors.go index 4e2b3a9eb..8c53044c6 100644 --- a/pkg/server/gqlutils/errors.go +++ b/pkg/server/gqlutils/errors.go @@ -94,6 +94,20 @@ func NDASignatureRequiredf(ctx context.Context, format string, a ...any) *gqlerr return NDASignatureRequired(ctx, fmt.Errorf(format, a...)) } +func AccountAlreadyActivated(ctx context.Context, err error) *gqlerror.Error { + return &gqlerror.Error{ + Message: err.Error(), + Path: graphql.GetPath(ctx), + Extensions: map[string]any{ + "code": "ACCOUNT_ALREADY_ACTIVATED", + }, + } +} + +func AccountAlreadyActivatedf(ctx context.Context, format string, a ...any) *gqlerror.Error { + return AccountAlreadyActivated(ctx, fmt.Errorf(format, a...)) +} + func Forbidden(ctx context.Context, err error) *gqlerror.Error { return &gqlerror.Error{ Message: err.Error(),