auth
import "github.com/nathabonfim59/pbvex/backend/internal/auth"Index
- func IsSuperuserRequest(e *core.RequestEvent) bool
- func SanitizedRequestID(value string) string
- func ToMap(identity *UserIdentity) map[string]any
- func WithInvocationMetadata(ctx context.Context, identity *UserIdentity, requestID string) context.Context
- type InvocationMetadata
- type UserIdentity
func IsSuperuserRequest
func IsSuperuserRequest(e *core.RequestEvent) boolIsSuperuserRequest returns true if the request event has a valid superuser auth record.
func SanitizedRequestID
func SanitizedRequestID(value string) stringSanitizedRequestID validates and normalizes an X-Request-Id header. If the value is missing or malformed, a new UUID is returned. Valid values are alphanumeric plus hyphen/underscore, between 1 and 64 characters.
func ToMap
func ToMap(identity *UserIdentity) map[string]anyToMap converts a UserIdentity to a plain map so it can be exported to Goja. It includes only the non-zero optional fields.
func WithInvocationMetadata
func WithInvocationMetadata(ctx context.Context, identity *UserIdentity, requestID string) context.Contexttype InvocationMetadata
InvocationMetadata is immutable request identity propagated through calls, realtime reruns, and nested runtime work.
type InvocationMetadata struct {
Identity *UserIdentity
RequestID string
}func InvocationMetadataFromContext
func InvocationMetadataFromContext(ctx context.Context) InvocationMetadatatype UserIdentity
UserIdentity is the stable, portable representation of an authenticated user inside the PBVex runtime. It deliberately mirrors the shape expected by Convex-compatible code so that user code can be moved between runtimes.
The fields are derived from the PocketBase auth record and are not based on any client-supplied claims. Superusers do not receive a UserIdentity from ctx.auth.getUserIdentity(); they are not application users.
type UserIdentity struct {
// Subject is a stable identifier for the end-user within the issuer.
// For PocketBase records this is the record id.
Subject string `json:"subject"`
// TokenIdentifier is a globally unique string for this identity.
// It combines the issuer and the subject so it is safe across multiple
// auth collections.
TokenIdentifier string `json:"tokenIdentifier"`
// Issuer identifies the identity provider. For PocketBase records it is
// the collection name qualified with a "pocketbase" namespace.
Issuer string `json:"issuer"`
// Standard OIDC profile claims. All optional fields are omitted from the
// JSON representation when empty.
Name string `json:"name,omitempty"`
GivenName string `json:"givenName,omitempty"`
FamilyName string `json:"familyName,omitempty"`
Nickname string `json:"nickname,omitempty"`
PreferredUsername string `json:"preferredUsername,omitempty"`
ProfileUrl string `json:"profileUrl,omitempty"`
PictureUrl string `json:"pictureUrl,omitempty"`
Email string `json:"email,omitempty"`
EmailVerified bool `json:"emailVerified,omitempty"`
Gender string `json:"gender,omitempty"`
Birthday string `json:"birthday,omitempty"`
Timezone string `json:"timezone,omitempty"`
Language string `json:"language,omitempty"`
PhoneNumber string `json:"phoneNumber,omitempty"`
PhoneNumberVerified bool `json:"phoneNumberVerified,omitempty"`
Address string `json:"address,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
}func FromRecord
func FromRecord(record *core.Record) *UserIdentityFromRecord maps a PocketBase auth record to a UserIdentity. It returns nil for nil records and for superusers, preventing superusers from gaining an application identity.
func IdentityFromRequest
func IdentityFromRequest(e *core.RequestEvent) *UserIdentityIdentityFromRequest returns the user identity for the authenticated record on a request event, or nil if the request is unauthenticated or the auth record is a superuser.
Generated by gomarkdoc