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) => {
|
onCompleted: (response: ActivateAccountPageMutation$data, errors: GraphQLError[] | null) => {
|
||||||
if (errors) {
|
if (errors) {
|
||||||
for (const err of errors) {
|
for (const err of errors) {
|
||||||
if (err.extensions?.code === "ALREADY_AUTHENTICATED") {
|
if (err.extensions?.code === "ACCOUNT_ALREADY_ACTIVATED") {
|
||||||
window.location.href = "/";
|
void navigate({
|
||||||
|
pathname: safeContinueUrl.pathname,
|
||||||
|
search: safeContinueUrl.search,
|
||||||
|
}, { replace: true });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// FIXME: If already activated redirect too
|
|
||||||
}
|
}
|
||||||
toast({
|
toast({
|
||||||
title: __("Activation failed"),
|
title: __("Activation failed"),
|
||||||
|
|||||||
@@ -379,14 +379,12 @@ func (r *mutationResolver) ActivateAccount(ctx context.Context, input types.Acti
|
|||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var (
|
var (
|
||||||
errInvalidToken *iam.ErrInvalidToken
|
errInvalidToken *iam.ErrInvalidToken
|
||||||
errInvitationNotFound *iam.ErrInvitationNotFound
|
errInvitationNotFound *iam.ErrInvitationNotFound
|
||||||
errInvitationAlreadyAccepted *iam.ErrInvitationAlreadyAccepted
|
errInvitationExpired *iam.ErrInvitationExpired
|
||||||
errInvitationExpired *iam.ErrInvitationExpired
|
|
||||||
|
|
||||||
isInvalidErr = errors.As(err, &errInvalidToken) ||
|
isInvalidErr = errors.As(err, &errInvalidToken) ||
|
||||||
errors.As(err, &errInvitationNotFound) ||
|
errors.As(err, &errInvitationNotFound) ||
|
||||||
errors.As(err, &errInvitationAlreadyAccepted) ||
|
|
||||||
errors.As(err, &errInvitationExpired)
|
errors.As(err, &errInvitationExpired)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -394,6 +392,10 @@ func (r *mutationResolver) ActivateAccount(ctx context.Context, input types.Acti
|
|||||||
return nil, gqlutils.Invalid(ctx, err)
|
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))
|
r.logger.ErrorCtx(ctx, "cannot activate account from invitation", log.Error(err))
|
||||||
return nil, gqlutils.Internal(ctx)
|
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...))
|
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 {
|
func Forbidden(ctx context.Context, err error) *gqlerror.Error {
|
||||||
return &gqlerror.Error{
|
return &gqlerror.Error{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
|
|||||||
Reference in New Issue
Block a user