supertokens

package
v0.10.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2023 License: Apache-2.0 Imports: 22 Imported by: 142

Documentation

Index

Constants

View Source
const (
	HeaderRID = "rid"
	HeaderFDI = "fdi-version"
)
View Source
const DashboardVersion = "0.6"
View Source
const VERSION = "0.10.8"

VERSION current version of the lib

Variables

View Source
var (
	QuerierHosts  []QuerierHost = nil
	QuerierAPIKey *string
)
View Source
var IsTestFlag = false

this will be set to true if this is used in a test app environment

Functions

func AddPostInitCallback added in v0.9.0

func AddPostInitCallback(cb func() error)

func ConvertGeneralErrorToJsonResponse added in v0.7.0

func ConvertGeneralErrorToJsonResponse(resp GeneralErrorResponse) map[string]interface{}

func DeleteUser added in v0.3.3

func DeleteUser(userId string) error

func ErrorHandler

func ErrorHandler(err error, req *http.Request, res http.ResponseWriter) error

func ErrorIfNoResponse added in v0.7.1

func ErrorIfNoResponse(res http.ResponseWriter) error

func GetAllCORSHeaders

func GetAllCORSHeaders() []string

func GetInstanceOrThrowError added in v0.2.0

func GetInstanceOrThrowError() (*superTokens, error)

func GetTopLevelDomainForSameSiteResolution added in v0.10.0

func GetTopLevelDomainForSameSiteResolution(URL string) (string, error)

func GetUserCount

func GetUserCount(includeRecipeIds *[]string) (float64, error)

func HumaniseMilliseconds added in v0.6.8

func HumaniseMilliseconds(m uint64) string

func Init

func Init(config TypeInput) error

func IsAnIPAddress

func IsAnIPAddress(ipaddress string) (bool, error)

func IsRunningInTestMode

func IsRunningInTestMode() bool

func LogDebugMessage added in v0.5.5

func LogDebugMessage(message string)

func MaxVersion added in v0.10.5

func MaxVersion(version1 string, version2 string) string

MaxVersion returns max of v1 and v2

func Middleware

func Middleware(theirHandler http.Handler) http.Handler

func ReadFromRequest added in v0.6.5

func ReadFromRequest(r *http.Request) ([]byte, error)

func ResetForTest

func ResetForTest()

func ResetQuerierForTest

func ResetQuerierForTest()

func Send200Response

func Send200Response(res http.ResponseWriter, responseJson interface{}) error

func SendHTMLResponse added in v0.9.1

func SendHTMLResponse(res http.ResponseWriter, statusCode int, htmlString string) error

func SendNon200Response

func SendNon200Response(res http.ResponseWriter, statusCode int, body map[string]interface{}) error

func SendNon200ResponseWithMessage added in v0.9.0

func SendNon200ResponseWithMessage(res http.ResponseWriter, message string, statusCode int) error

func SendUnauthorisedAccess added in v0.9.1

func SendUnauthorisedAccess(res http.ResponseWriter) error

Types

type APIHandled

type APIHandled struct {
	PathWithoutAPIBasePath NormalisedURLPath
	Method                 string
	ID                     string
	Disabled               bool
}

type AppInfo

type AppInfo struct {
	AppName         string
	WebsiteDomain   string
	APIDomain       string
	WebsiteBasePath *string
	APIBasePath     *string
	APIGatewayPath  *string
}

type BadInputError

type BadInputError struct {
	Msg string
}

BadInputError used for non specific exceptions

func (BadInputError) Error

func (err BadInputError) Error() string

type ConnectionInfo

type ConnectionInfo struct {
	ConnectionURI string
	APIKey        string
}

type CreateUserIdMappingResult added in v0.8.3

type CreateUserIdMappingResult struct {
	OK                              *struct{}
	UnknownSupertokensUserIdError   *struct{}
	UserIdMappingAlreadyExistsError *struct {
		DoesSuperTokensUserIdExist bool
		DoesExternalUserIdExist    bool
	}
}

func CreateUserIdMapping added in v0.8.3

func CreateUserIdMapping(supertokensUserId string, externalUserId string, externalUserIdInfo *string, force *bool) (CreateUserIdMappingResult, error)

type DeleteUserIdMappingResult added in v0.8.3

type DeleteUserIdMappingResult struct {
	OK *struct {
		DidMappingExist bool
	}
}

func DeleteUserIdMapping added in v0.8.3

func DeleteUserIdMapping(userId string, userIdType *UserIdType, force *bool) (DeleteUserIdMappingResult, error)

type DoneWriter added in v0.2.2

type DoneWriter interface {
	http.ResponseWriter
	IsDone() bool
}

func MakeDoneWriter added in v0.3.5

func MakeDoneWriter(w http.ResponseWriter) DoneWriter

WrapWriter wraps an http.ResponseWriter, returning a proxy that allows you to hook into various parts of the response process.

type GeneralErrorResponse added in v0.7.0

type GeneralErrorResponse struct {
	Message string
}

type GetUserIdMappingResult added in v0.8.3

type GetUserIdMappingResult struct {
	OK *struct {
		SupertokensUserId  string
		ExternalUserId     string
		ExternalUserIdInfo *string
	}
	UnknownMappingError *struct{}
}

func GetUserIdMapping added in v0.8.3

func GetUserIdMapping(userId string, userIdType *UserIdType) (GetUserIdMappingResult, error)

type NormalisedAppinfo

type NormalisedAppinfo struct {
	AppName               string
	WebsiteDomain         NormalisedURLDomain
	APIDomain             NormalisedURLDomain
	TopLevelAPIDomain     string
	TopLevelWebsiteDomain string
	APIBasePath           NormalisedURLPath
	APIGatewayPath        NormalisedURLPath
	WebsiteBasePath       NormalisedURLPath
}

func NormaliseInputAppInfoOrThrowError

func NormaliseInputAppInfoOrThrowError(appInfo AppInfo) (NormalisedAppinfo, error)

type NormalisedURLDomain

type NormalisedURLDomain struct {
	// contains filtered or unexported fields
}

func NewNormalisedURLDomain

func NewNormalisedURLDomain(url string) (NormalisedURLDomain, error)

func (NormalisedURLDomain) GetAsStringDangerous

func (n NormalisedURLDomain) GetAsStringDangerous() string

type NormalisedURLPath

type NormalisedURLPath struct {
	// contains filtered or unexported fields
}

func NewNormalisedURLPath

func NewNormalisedURLPath(url string) (NormalisedURLPath, error)

func (NormalisedURLPath) AppendPath

func (NormalisedURLPath) Equals

func (n NormalisedURLPath) Equals(other NormalisedURLPath) bool

func (NormalisedURLPath) GetAsStringDangerous

func (n NormalisedURLPath) GetAsStringDangerous() string

func (NormalisedURLPath) IsARecipePath

func (n NormalisedURLPath) IsARecipePath() bool

func (NormalisedURLPath) StartsWith

func (n NormalisedURLPath) StartsWith(other NormalisedURLPath) bool

type Querier

type Querier struct {
	RIDToCore string
}

func GetNewQuerierInstanceOrThrowError

func GetNewQuerierInstanceOrThrowError(rIDToCore string) (*Querier, error)

func (*Querier) GetQuerierAPIVersion added in v0.5.2

func (q *Querier) GetQuerierAPIVersion() (string, error)

func (*Querier) SendDeleteRequest

func (q *Querier) SendDeleteRequest(path string, data map[string]interface{}, params map[string]string) (map[string]interface{}, error)

func (*Querier) SendGetRequest

func (q *Querier) SendGetRequest(path string, params map[string]string) (map[string]interface{}, error)

func (*Querier) SendPostRequest

func (q *Querier) SendPostRequest(path string, data map[string]interface{}) (map[string]interface{}, error)

func (*Querier) SendPutRequest

func (q *Querier) SendPutRequest(path string, data map[string]interface{}) (map[string]interface{}, error)

type QuerierHost added in v0.4.2

type QuerierHost struct {
	Domain   NormalisedURLDomain
	BasePath NormalisedURLPath
}

type Recipe

type Recipe func(appInfo NormalisedAppinfo, onSuperTokensAPIError func(err error, req *http.Request, res http.ResponseWriter)) (*RecipeModule, error)

type RecipeModule

type RecipeModule struct {
	HandleAPIRequest              func(ID string, req *http.Request, res http.ResponseWriter, theirHandler http.HandlerFunc, path NormalisedURLPath, method string) error
	GetAllCORSHeaders             func() []string
	GetAPIsHandled                func() ([]APIHandled, error)
	ReturnAPIIdIfCanHandleRequest func(path NormalisedURLPath, method string) (*string, error)
	HandleError                   func(err error, req *http.Request, res http.ResponseWriter) (bool, error)
	OnSuperTokensAPIError         func(err error, req *http.Request, res http.ResponseWriter)
	// contains filtered or unexported fields
}

func MakeRecipeModule

func MakeRecipeModule(
	recipeId string,
	appInfo NormalisedAppinfo,
	handleAPIRequest func(id string, req *http.Request, res http.ResponseWriter, theirHandler http.HandlerFunc, path NormalisedURLPath, method string) error,
	getAllCORSHeaders func() []string,
	getAPIsHandled func() ([]APIHandled, error),
	returnAPIIdIfCanHandleRequest func(path NormalisedURLPath, method string) (*string, error),
	handleError func(err error, req *http.Request, res http.ResponseWriter) (bool, error),
	onSuperTokensAPIError func(err error, req *http.Request, res http.ResponseWriter)) RecipeModule

func (RecipeModule) GetAppInfo

func (r RecipeModule) GetAppInfo() NormalisedAppinfo

func (RecipeModule) GetRecipeID

func (r RecipeModule) GetRecipeID() string

type TypeInput

type TypeInput struct {
	Supertokens           *ConnectionInfo
	AppInfo               AppInfo
	RecipeList            []Recipe
	Telemetry             *bool
	OnSuperTokensAPIError func(err error, req *http.Request, res http.ResponseWriter)
}

type UpdateOrDeleteUserIdMappingInfoResult added in v0.8.3

type UpdateOrDeleteUserIdMappingInfoResult struct {
	OK                  *struct{}
	UnknownMappingError *struct{}
}

func UpdateOrDeleteUserIdMappingInfo added in v0.8.3

func UpdateOrDeleteUserIdMappingInfo(userId string, userIdType *UserIdType, externalUserIdInfo *string) (UpdateOrDeleteUserIdMappingInfoResult, error)

type UserContext added in v0.4.0

type UserContext = *map[string]interface{}

func MakeDefaultUserContextFromAPI added in v0.8.0

func MakeDefaultUserContextFromAPI(r *http.Request) UserContext

type UserIdType added in v0.8.3

type UserIdType string
const (
	UserIdTypeAny         UserIdType = "ANY"
	UserIdTypeSupertokens UserIdType = "SUPERTOKENS"
	UserIdTypeExternal    UserIdType = "EXTERNAL"
)

type UserPaginationResult

type UserPaginationResult struct {
	Users []struct {
		RecipeId string                 `json:"recipeId"`
		User     map[string]interface{} `json:"user"`
	}
	NextPaginationToken *string
}

func GetUsersNewestFirst

func GetUsersNewestFirst(paginationToken *string, limit *int, includeRecipeIds *[]string) (UserPaginationResult, error)

func GetUsersOldestFirst

func GetUsersOldestFirst(paginationToken *string, limit *int, includeRecipeIds *[]string) (UserPaginationResult, error)

func GetUsersWithSearchParams added in v0.10.5

func GetUsersWithSearchParams(timeJoinedOrder string, paginationToken *string, limit *int, includeRecipeIds *[]string, searchParams map[string]string) (UserPaginationResult, error)

TODO: Add tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL