service

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExpiredToken  = errors.New("token expired")
	JWTSigningMethod = jwt.SigningMethodES512
)

Functions

func Module

func Module() fx.Option

Types

type Auth

type Auth struct {
	fx.In

	Config      *appconfig.Config
	Ent         *ent.Client
	Redis       *redis.Client
	JWT         JWT
	Turnstile   Turnstile
	MailService Mail
}

func (Auth) AuthByLoginInput

func (s Auth) AuthByLoginInput(ctx context.Context, args model.LoginInput) (*ent.User, error)

func (Auth) AuthByToken

func (s Auth) AuthByToken(ctx context.Context, token string) (*ent.User, error)

func (Auth) CreateUser

func (s Auth) CreateUser(ctx context.Context, args model.CreateUserInput) (*ent.User, error)

func (Auth) CurrentUser

func (s Auth) CurrentUser(ctx context.Context) (*ent.User, error)

func (Auth) RequestPasswordReset added in v0.0.5

func (s Auth) RequestPasswordReset(ctx context.Context, input model.RequestPasswordResetInput) (bool, error)

func (Auth) ResetPassword added in v0.0.5

func (s Auth) ResetPassword(ctx context.Context, input model.ResetPasswordInput) (bool, error)

func (Auth) SetUserToken

func (s Auth) SetUserToken(ctx context.Context, user *ent.User) error

type Directive

type Directive struct {
	fx.In
}

func (Directive) Admin

func (s Directive) Admin(ctx context.Context, obj any, next graphql.Resolver) (res any, err error)

Admin directive is used to check if the current user is an admin. if not, return error.

func (Directive) Private

func (s Directive) Private(ctx context.Context, obj any, next graphql.Resolver, userIDFieldName *string) (res any, err error)

Private directive is used to check if the current user is the owner of the object. if not, return null for the field.

type Event

type Event struct {
	fx.In

	Ent         *ent.Client
	AuthService Auth
}

func (Event) CalculateStats

func (s Event) CalculateStats(ctx context.Context, researchID string, filterInput string, resultMappingInput string) (*model.GroupCountResult, error)

*

  • CalculateStats filters events by filterInput and maps every event to a result using resultMappingInput, then group by result and count
  • @param {string} filterInput can be jsonLogic or expr expression, depends on the filter implementation
  • @param {string} resultMappingInput must be an expr expression

func (Event) CreateEventFromInput

func (s Event) CreateEventFromInput(ctx context.Context, input model.CreateEventInput) (*ent.Event, error)

type JWT

type JWT struct {
	Config *appconfig.Config
	// contains filtered or unexported fields
}

func NewJWT

func NewJWT(config *appconfig.Config) (JWT, error)

func (*JWT) Sign

func (s *JWT) Sign(userId string) (string, error)

Sign signs a JWT token with the given user ID as the `sub` claim.

func (*JWT) Verify

func (s *JWT) Verify(token string) (sub string, t time.Time, err error)

Verify verifies the token and returns the user ID (`sub` claim) along with the expiration time if the token is valid.

type Mail

type Mail struct {
	fx.In

	ResendClient *resend.Client
}

func (Mail) Send

func (s Mail) Send(r *SendEmailRequest) (string, error)

type SendEmailRequest

type SendEmailRequest struct {
	To      []string
	Subject string
	Html    string
	Text    string
}

type Turnstile

type Turnstile struct {
	Config *appconfig.Config
	// contains filtered or unexported fields
}

func NewTurnstile

func NewTurnstile(config *appconfig.Config) Turnstile

func (Turnstile) Verify

func (s Turnstile) Verify(ctx context.Context, turnstileResponse, expectedAction string) error

Jump to

Keyboard shortcuts

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