1
0
forked from baron/baron-sso

변수 이름 수정

This commit is contained in:
2026-01-13 10:31:18 +09:00
parent ee9f835ceb
commit 59b5f8f7e9

View File

@@ -19,6 +19,19 @@ import (
"github.com/gofiber/fiber/v2"
)
const (
// Redis Key Prefixes
prefixSession = "enchanted_session:"
prefixToken = "enchanted_token:"
// Session Statuses
statusPending = "pending"
statusSuccess = "success"
// Durations
defaultExpiration = 5 * time.Minute
)
type AuthHandler struct {
ProjectID string
SmsService domain.SmsService
@@ -124,8 +137,8 @@ func (h *AuthHandler) InitEnchantedLink(c *fiber.Ctx) error {
pendingRef := generateSecureToken(4)
// Store in Redis
h.RedisService.Set("enchanted_session:"+pendingRef, `{"status":"pending"}`, 5*time.Minute)
h.RedisService.Set("enchanted_token:"+token, fmt.Sprintf(`{"pendingRef":"%s","loginId":"%s"}`, pendingRef, loginID), 5*time.Minute)
h.RedisService.Set(prefixSession+pendingRef, fmt.Sprintf(`{"status":"%s"}`, statusPending), defaultExpiration)
h.RedisService.Set(prefixToken+token, fmt.Sprintf(`{"pendingRef":"%s","loginId":"%s"}`, pendingRef, loginID), defaultExpiration)
// Send SMS
// Frontend URL should be dynamic or env based, but restoring hardcoded/env logic
@@ -155,22 +168,22 @@ func (h *AuthHandler) PollEnchantedLink(c *fiber.Ctx) error {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request body"})
}
val, err := h.RedisService.Get("enchanted_session:" + req.PendingRef)
val, err := h.RedisService.Get(prefixSession + req.PendingRef)
if err != nil || val == "" {
return c.JSON(fiber.Map{"status": "pending"})
return c.JSON(fiber.Map{"status": statusPending})
}
var data map[string]string
json.Unmarshal([]byte(val), &data)
if data["status"] == "success" {
if data["status"] == statusSuccess {
return c.JSON(fiber.Map{
"sessionJwt": data["jwt"],
"status": "ok",
})
}
return c.JSON(fiber.Map{"status": "pending"})
return c.JSON(fiber.Map{"status": statusPending})
}
// VerifyMagicLink - Validate token and login (Restored)
@@ -180,14 +193,14 @@ func (h *AuthHandler) VerifyMagicLink(c *fiber.Ctx) error {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request body"})
}
tokenKey := "enchanted_token:" + req.Token
tokenKey := prefixToken + req.Token
val, err := h.RedisService.Get(tokenKey)
if err != nil || val == "" {
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{"error": "Invalid or expired token"})
}
var tokenData map[string]string
json.Unmarshal([]byte(val), &data := tokenData)
json.Unmarshal([]byte(val), &tokenData)
pendingRef := tokenData["pendingRef"]
loginID := tokenData["loginId"]
@@ -247,10 +260,10 @@ func (h *AuthHandler) VerifyMagicLink(c *fiber.Ctx) error {
// Update Session in Redis for the polling client
sessionData, _ := json.Marshal(map[string]string{
"status": "success",
"status": statusSuccess,
"jwt": sessionToken,
})
h.RedisService.Set("enchanted_session:"+pendingRef, string(sessionData), 5*time.Minute)
h.RedisService.Set(prefixSession+pendingRef, string(sessionData), defaultExpiration)
return c.JSON(fiber.Map{
"token": sessionToken,