diff --git a/backend/db/db.go b/backend/db/db.go index 25a214c..620e498 100644 --- a/backend/db/db.go +++ b/backend/db/db.go @@ -137,30 +137,6 @@ func (db *DB) GetJSON(ctx context.Context, key string, v any) error { return nil } -// GetDelJSON gets the given key as a JSON object and deletes it. -func (db *DB) GetDelJSON(ctx context.Context, key string, v any) error { - var b []byte - - err := db.Redis.Do(ctx, radix.Cmd(&b, "GETDEL", key)) - if err != nil { - return errors.Wrap(err, "reading from Redis") - } - - if b == nil { - return nil - } - - if v == nil { - return fmt.Errorf("nil pointer passed into GetDelJSON") - } - - err = json.Unmarshal(b, v) - if err != nil { - return errors.Wrap(err, "unmarshaling json") - } - return nil -} - // NotNull is a little helper that returns an *empty slice* when the slice's length is 0. // This is to prevent nil slices from being marshaled as JSON null func NotNull[T any](slice []T) []T { diff --git a/backend/routes/auth/undelete.go b/backend/routes/auth/undelete.go index a09cb36..5c8643e 100644 --- a/backend/routes/auth/undelete.go +++ b/backend/routes/auth/undelete.go @@ -67,7 +67,7 @@ func (s *Server) saveUndeleteToken(ctx context.Context, userID xid.ID, token str func (s *Server) getUndeleteToken(ctx context.Context, token string) (userID xid.ID, err error) { var idString string - err = s.DB.Redis.Do(ctx, radix.Cmd(&idString, "GETDEL", "undelete:"+token)) + err = s.DB.Redis.Do(ctx, radix.Cmd(&idString, "GET", "undelete:"+token)) if err != nil { return userID, errors.Wrap(err, "getting undelete key") } @@ -76,6 +76,11 @@ func (s *Server) getUndeleteToken(ctx context.Context, token string) (userID xid if err != nil { return userID, errors.Wrap(err, "parsing ID") } + + err = s.DB.Redis.Do(ctx, radix.Cmd(nil, "DEL", "undelete:"+token)) + if err != nil { + return userID, errors.Wrap(err, "deleting undelete key") + } return userID, nil }