skip token expired for login mutation

This commit is contained in:
Nimer Farahty 2025-06-09 01:53:17 +03:00
parent 7949a93dcb
commit b0120532af
4 changed files with 7 additions and 2 deletions

View File

@ -57,6 +57,7 @@ func CurrentUser(ctx context.Context) (*models.UserJWT, error) {
// Check if the token was marked as expired
func IsTokenExpired(ctx context.Context) bool {
if expired, ok := ctx.Value(ExpiryKey).(bool); ok {
return expired
}

View File

@ -114,6 +114,10 @@ func AuthorizeOperation(ctx context.Context) error {
return nil
}
if IsTokenExpired(ctx) && object != "login" {
return fmt.Errorf("token expired")
}
if obj, err := CurrentUser(ctx); err == nil {
user = string(obj.ID)
}

View File

@ -12,7 +12,7 @@ import (
"github.com/golang-jwt/jwt/v4"
)
// Middleware injects dataloaders into context for each HTTP request
// Middleware injects dataLoaders into context for each HTTP request
func LoaderMiddleware(loaders *Loaders, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctxWithLoaders := context.WithValue(r.Context(), LoadersKey, loaders)

View File

@ -91,7 +91,7 @@ func createGraphqlServer() http.Handler {
// Apply global middleware
srv.AroundRootFields(app.RootFieldsAuthorizer) // Check for @auth at root fields
srv.AroundResponses(app.ExpiryMiddleware) // Token expiry validation
//srv.AroundResponses(app.ExpiryMiddleware) // Token expiry validation
// Inject DataLoaders into request context
return app.LoaderMiddleware(app.NewLoaders(), srv)