package auth

import (
	"net/http"
	"strings"
)

func getToken(r *http.Request) (string, bool) {
	authHeader := r.Header.Get("Authorization")
	if authHeader != "" {
		parts := strings.Split(authHeader, " ")
		if len(parts) != 2 {
			return "", false
		}
		return parts[1], true
	}
	c, err := r.Cookie("token")
	if err != nil {
		return "", false
	}
	return c.Value, true
}
