Skip to content

auth

go
import "github.com/nathabonfim59/pbvex/backend/internal/auth"

Index

func IsSuperuserRequest

go
func IsSuperuserRequest(e *core.RequestEvent) bool

IsSuperuserRequest returns true if the request event has a valid superuser auth record.

func SanitizedRequestID

go
func SanitizedRequestID(value string) string

SanitizedRequestID 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

go
func ToMap(identity *UserIdentity) map[string]any

ToMap converts a UserIdentity to a plain map so it can be exported to Goja. It includes only the non-zero optional fields.

func WithInvocationMetadata

go
func WithInvocationMetadata(ctx context.Context, identity *UserIdentity, requestID string) context.Context

type InvocationMetadata

InvocationMetadata is immutable request identity propagated through calls, realtime reruns, and nested runtime work.

go
type InvocationMetadata struct {
    Identity  *UserIdentity
    RequestID string
}

func InvocationMetadataFromContext

go
func InvocationMetadataFromContext(ctx context.Context) InvocationMetadata

type 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.

go
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

go
func FromRecord(record *core.Record) *UserIdentity

FromRecord 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

go
func IdentityFromRequest(e *core.RequestEvent) *UserIdentity

IdentityFromRequest 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

Generated API reference. Source of truth is the codebase.