Catch account already activated error and redirect

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-03-11 14:25:05 +04:00
parent 961980f852
commit af17afeffb
3 changed files with 26 additions and 8 deletions

View File

@@ -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"),

View File

@@ -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)
}

View File

@@ -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(),