Use TokenSize const in api common.go

pull/4/head
maru 9 months ago
parent 39199dc1b1
commit 25abf4914b
No known key found for this signature in database
GPG Key ID: 37689350E9CD0F0D

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"github.com/pagefaultgames/pokerogue-server/api/account"
"github.com/pagefaultgames/pokerogue-server/api/daily" "github.com/pagefaultgames/pokerogue-server/api/daily"
"github.com/pagefaultgames/pokerogue-server/db" "github.com/pagefaultgames/pokerogue-server/db"
) )
@ -24,8 +25,8 @@ func getUsernameFromRequest(r *http.Request) (string, error) {
return "", fmt.Errorf("failed to decode token: %s", err) return "", fmt.Errorf("failed to decode token: %s", err)
} }
if len(token) != 32 { if len(token) != account.TokenSize {
return "", fmt.Errorf("invalid token length: got %d, expected 32", len(token)) return "", fmt.Errorf("invalid token length: got %d, expected %d", len(token), account.TokenSize)
} }
username, err := db.FetchUsernameFromToken(token) username, err := db.FetchUsernameFromToken(token)
@ -46,8 +47,8 @@ func getUUIDFromRequest(r *http.Request) ([]byte, error) {
return nil, fmt.Errorf("failed to decode token: %s", err) return nil, fmt.Errorf("failed to decode token: %s", err)
} }
if len(token) != 32 { if len(token) != account.TokenSize {
return nil, fmt.Errorf("invalid token length: got %d, expected 32", len(token)) return nil, fmt.Errorf("invalid token length: got %d, expected %d", len(token), account.TokenSize)
} }
uuid, err := db.FetchUUIDFromToken(token) uuid, err := db.FetchUUIDFromToken(token)

Loading…
Cancel
Save