Documentation
¶
Overview ¶
Package stdentsaas provides re-usable SaaS code using Ent as the ORM.
Index ¶
- func AuthenticatedUser(ctx context.Context) (string, bool)
- func WithAuthenticatedOrganizations(ctx context.Context, first OrganizationRole, more ...OrganizationRole) context.Context
- func WithAuthenticatedUser(ctx context.Context, userID string) context.Context
- type Driver
- type DriverOption
- type OrganizationRole
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthenticatedUser ¶
AuthenticatedUser returns the user that the context is authenticated for.
func WithAuthenticatedOrganizations ¶
func WithAuthenticatedOrganizations( ctx context.Context, first OrganizationRole, more ...OrganizationRole, ) context.Context
WithAuthenticatedOrganizations declares on the context that any calls carrying the context has access to these organizations with the provided role.
Types ¶
type Driver ¶
type Driver struct {
entdialect.Driver
// contains filtered or unexported fields
}
Driver is an opionated Ent driver that wraps a base driver but only allows interactions with the database to be done through a transaction with specific isolation properties and auth settings applied properly.
func NewDriver ¶
func NewDriver( base entdialect.Driver, opts ...DriverOption, ) *Driver
NewDriver inits the driver.
func (Driver) BeginTx ¶
BeginTx calls the base driver's method if it's supported and calls our hook.
func (Driver) Exec ¶
Exec executes a query that does not return records. For example, in SQL, INSERT or UPDATE. It scans the result into the pointer v. For SQL drivers, it is dialect/sql.Result.
type DriverOption ¶
type DriverOption func(*Driver)
func AnonymousUserID ¶
func AnonymousUserID(s string) DriverOption
AnonymousUserID configures the id that will be used in the setting when the user is not authenticated.
func AuthenticatedOrganizationsSetting ¶
func AuthenticatedOrganizationsSetting(s string) DriverOption
AuthenticatedOrganizationsSetting configures the transaction-scoped postgres setting that will cary which organizations the user is autthenticated for.
func AuthenticatedUserSetting ¶
func AuthenticatedUserSetting(s string) DriverOption
AuthenticatedUserSetting configures the transaction-scoped postgres setting that will cary which user is authenticated for.
type OrganizationRole ¶
type OrganizationRole struct {
OrganizationID string `json:"organization_id"`
Role string `json:"role"`
}
OrganizationRole describes a role in an organization. Both fields are encoded as strings such that RLS policies can easily cast it to a type that is relevant in the schema at hand, such as UUID or an enum.
func AuthenticatedOrganizations ¶
func AuthenticatedOrganizations(ctx context.Context) (ors []OrganizationRole, ok bool)
AuthenticatedOrganizations returns the organization and roles from the context or panic.