Skip to content

Commit

Permalink
comment out
Browse files Browse the repository at this point in the history
  • Loading branch information
alldoami committed Feb 4, 2025
1 parent e433179 commit ea3081f
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/http"
"os"
"strings"
"time"

"github.com/gofiber/fiber/v2"
)
Expand Down Expand Up @@ -94,6 +93,8 @@ func queryRecipient(email string) (*RecipientResponse, error) {

if resp.StatusCode == http.StatusOK {
var recipient RecipientResponse
fmt.Printf("Recipient response body: %+v\n", resp.Body)
fmt.Print(json.NewDecoder(resp.Body).Decode(&recipient))
if err := json.NewDecoder(resp.Body).Decode(&recipient); err != nil {
return nil, fmt.Errorf("error parsing recipient response: %w", err)
}
Expand Down Expand Up @@ -131,8 +132,9 @@ func createRecipient(email string) (string, error) {
return "", fmt.Errorf("no tokens returned for new recipient")
}

fmt.Printf("Recipient '%s' created successfully. Activation link: %s\n", recipientName, recipient.Recipients[0].Tokens[0].ActivationURL)
return recipient.Recipients[0].Tokens[0].ActivationURL, nil
// fmt.Printf("Recipient '%s' created successfully. Activation link: %s\n", recipientName, recipient.Recipients[0].Tokens[0].ActivationURL)
// return recipient.Recipients[0].Tokens[0].ActivationURL, nil
return "trying to send activation link", nil
}

return "", fmt.Errorf("failed to create recipient: %d", resp.StatusCode)
Expand All @@ -159,8 +161,9 @@ func rotateToken(email string, expireInSeconds int) (string, error) {
return "", fmt.Errorf("no tokens returned after rotation")
}

fmt.Printf("Token rotated successfully. New activation link: %s\n", rotationResponse.Tokens[0].ActivationURL)
return rotationResponse.Tokens[0].ActivationURL, nil
// fmt.Printf("Token rotated successfully. New activation link: %s\n", rotationResponse.Tokens[0].ActivationURL)
// return rotationResponse.Tokens[0].ActivationURL, nil
return "trying to send activation link", nil
}

return "", fmt.Errorf("failed to rotate token: %d", resp.StatusCode)
Expand Down Expand Up @@ -228,19 +231,19 @@ func main() {

// Check token expiration
fmt.Printf("Recipient response: %+v\n", recipient)
expirationTime := recipient.Recipients[0].Tokens[0].ExpirationTime
currentTime := time.Now().Unix()

if expirationTime < currentTime {
fmt.Printf("Token for recipient '%s' has expired. Rotating...\n", recipient.Recipients[0].Name)
activationLink, err := rotateToken(email, expirationInSeconds)
if err != nil {
return c.Status(http.StatusInternalServerError).JSON(fiber.Map{"error": "Error rotating token: " + err.Error()})
}
return c.Status(http.StatusOK).JSON(fiber.Map{"message": fmt.Sprintf("Token for %s rotated", email), "activation_link": activationLink})
}

return c.Status(http.StatusOK).JSON(fiber.Map{"message": fmt.Sprintf("Token for %s is still valid", email), "activation_link": recipient.Recipients[0].Tokens[0].ActivationURL})
// expirationTime := recipient.Recipients[0].Tokens[0].ExpirationTime
// currentTime := time.Now().Unix()

// if expirationTime < currentTime {
// fmt.Printf("Token for recipient '%s' has expired. Rotating...\n", recipient.Recipients[0].Name)
// activationLink, err := rotateToken(email, expirationInSeconds)
// if err != nil {
// return c.Status(http.StatusInternalServerError).JSON(fiber.Map{"error": "Error rotating token: " + err.Error()})
// }
// return c.Status(http.StatusOK).JSON(fiber.Map{"message": fmt.Sprintf("Token for %s rotated", email), "activation_link": activationLink})
// }

// return c.Status(http.StatusOK).JSON(fiber.Map{"message": fmt.Sprintf("Token for %s is still valid", email), "activation_link": recipient.Recipients[0].Tokens[0].ActivationURL})
})

log.Fatal(app.Listen(":8080"))
Expand Down

0 comments on commit ea3081f

Please sign in to comment.