package auth

import (
	"context"
	"net/http"
)

type authkey int

const keyClaims = iota

func writeToContext(r *http.Request, claims *Claims) *http.Request {
	ctx := context.WithValue(r.Context(), keyClaims, claims)
	return r.WithContext(ctx)
}

// ExtractClaims extracts user claims from given context. If no claims in context ok = false.
func ExtractClaims(ctx context.Context) (claims *Claims, ok bool) {
	val := ctx.Value(keyClaims)
	claims, ok = val.(*Claims)
	return
}
