Add error for already used token

Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
Bryan Frimin
2026-06-05 17:54:51 +02:00
parent caeac0ed1c
commit d43526bff4
7 changed files with 82 additions and 1 deletions

View File

@@ -83,6 +83,10 @@ func (r *mutationResolver) VerifyMagicLink(ctx context.Context, input types.Veri
return nil, gqlutils.TokenExpired(ctx, err)
}
if _, ok := errors.AsType[*iam.ErrTokenAlreadyUsed](err); ok {
return nil, gqlutils.TokenAlreadyUsed(ctx, err)
}
if _, ok := errors.AsType[*iam.ErrInvalidToken](err); ok {
return nil, gqlutils.Invalid(ctx, err)
}
@@ -105,6 +109,10 @@ func (r *mutationResolver) VerifyMagicLink(ctx context.Context, input types.Veri
return nil, gqlutils.TokenExpired(ctx, err)
}
if _, ok := errors.AsType[*iam.ErrTokenAlreadyUsed](err); ok {
return nil, gqlutils.TokenAlreadyUsed(ctx, err)
}
if _, ok := errors.AsType[*iam.ErrInvalidToken](err); ok {
return nil, gqlutils.Invalid(ctx, err)
}

View File

@@ -150,6 +150,14 @@ func TokenExpired(ctx context.Context, err error) *gqlerror.Error {
}
}
func TokenAlreadyUsed(ctx context.Context, err error) *gqlerror.Error {
return &gqlerror.Error{
Message: err.Error(),
Path: graphql.GetPath(ctx),
Extensions: map[string]any{"code": "TOKEN_ALREADY_USED"},
}
}
func Invalid(ctx context.Context, err error) *gqlerror.Error {
var details map[string]any