Catch account already activated error and redirect
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -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"),
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user