Documentation
¶
Overview ¶
Package handler provides HTTP handlers for all operations, as well as middleware for authentication and authorization.
Index ¶
- func HTTPErrorHandler(err error, c echo.Context)
- func WithAuth() echo.MiddlewareFunc
- func WithUser() echo.MiddlewareFunc
- type AuthHandler
- func (h AuthHandler) HandleGetAuthCallback(c echo.Context) error
- func (h AuthHandler) HandleGetLogin(c echo.Context) error
- func (h AuthHandler) HandleGetLoginWithGoogle(c echo.Context) error
- func (h AuthHandler) HandleGetRegister(c echo.Context) error
- func (h AuthHandler) HandlePostLogin(c echo.Context) error
- func (h AuthHandler) HandlePostLogout(c echo.Context) error
- func (h AuthHandler) HandlePostRegister(c echo.Context) error
- type Authenticator
- type DashboardHandler
- type Deauthenticator
- type GoogleAuthenticator
- type HomeHandler
- type LocalAuthenticator
- type LocalDeauthenticator
- type LocalRegistrator
- type Registrator
- type SettingsHandler
- type SupabaseAuthenticator
- type SupabaseRegistrator
- type SupabaseVerifier
- type Verifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPErrorHandler ¶
func HTTPErrorHandler(err error, c echo.Context)
HTTPErrorHandler will be executed when an HTTP request fails.
Types ¶
type AuthHandler ¶
type AuthHandler struct {
// contains filtered or unexported fields
}
AuthHandler provides handlers for the authentication routes of the application. It is responsible for handling user login, registration, and logout.
func NewAuthHandler ¶
func NewAuthHandler() *AuthHandler
NewAuthHandler creates a new AuthHandler with the given LoginService and RegisterService, depending on the database type.
func (AuthHandler) HandleGetAuthCallback ¶
func (h AuthHandler) HandleGetAuthCallback(c echo.Context) error
HandleGetAuthCallback responds to GET on the /auth/callback route by verifying the user.
func (AuthHandler) HandleGetLogin ¶
func (h AuthHandler) HandleGetLogin(c echo.Context) error
HandleGetLogin responds to GET on the /login route by rendering the Login component.
func (AuthHandler) HandleGetLoginWithGoogle ¶
func (h AuthHandler) HandleGetLoginWithGoogle(c echo.Context) error
HandleGetLoginWithGoogle responds to GET on the /login/provider/google route by logging in the user with Google.
func (AuthHandler) HandleGetRegister ¶
func (h AuthHandler) HandleGetRegister(c echo.Context) error
HandleGetRegister responds to GET on the /register route by rendering the Register component.
func (AuthHandler) HandlePostLogin ¶
func (h AuthHandler) HandlePostLogin(c echo.Context) error
HandlePostLogin responds to POST on the /login route by trying to log in the user. If the user exists and the password is correct, the JWT tokens are generated and set as cookies. Finally, the user is redirected to the dashboard.
func (AuthHandler) HandlePostLogout ¶
func (h AuthHandler) HandlePostLogout(c echo.Context) error
HandlePostLogout responds to POST on the /logout route by logging out the user.
func (AuthHandler) HandlePostRegister ¶
func (h AuthHandler) HandlePostRegister(c echo.Context) error
HandlePostRegister responds to POST on the /register route by trying to register the user. If the user does not exist, the password is hashed and the user is created in the database. Afterwards, the JWT tokens are generated and set as cookies. Finally, the user is redirected to the dashboard.
type Authenticator ¶
type Authenticator interface { // Login signs in the user with the application Login(c echo.Context) error }
Authenticator is the interface that wraps the basic Login method.
func NewAuthenticator ¶
func NewAuthenticator() (Authenticator, error)
NewAuthenticator returns the correct Authenticator based on the DB_TYPE environment variable.
type DashboardHandler ¶
type DashboardHandler struct{}
DashboardHandler provides handlers for the dashboard route of the application.
func (*DashboardHandler) HandleGetDashboard ¶
func (h *DashboardHandler) HandleGetDashboard(c echo.Context) error
HandleGetDashboard responds to GET on the /dashboard route by rendering the Dashboard component.
type Deauthenticator ¶
type Deauthenticator interface { // Logout logs out the user Logout(c echo.Context) error }
Deauthenticator is the interface that wraps the basic Logout method.
type GoogleAuthenticator ¶
type GoogleAuthenticator struct{}
GoogleAuthenticator is an interface for the user login, when using Google.
func (GoogleAuthenticator) Login ¶
func (g GoogleAuthenticator) Login(c echo.Context) error
Login logs in the user with their Google Credentials
type HomeHandler ¶
type HomeHandler struct{}
HomeHandler provides handlers for the home route of the application.
func (*HomeHandler) HandleGetHome ¶
func (h *HomeHandler) HandleGetHome(c echo.Context) error
HandleGetHome responds to GET on the / route by redirecting to the dashboard if the user is logged in, otherwise to the login page.
type LocalAuthenticator ¶
type LocalAuthenticator struct{}
LocalAuthenticator is an interface for the user login, when using a local database.
func (LocalAuthenticator) Login ¶
func (l LocalAuthenticator) Login(c echo.Context) error
Login logs in the user with the local database.
type LocalDeauthenticator ¶
type LocalDeauthenticator struct{}
LocalDeauthenticator is an struct for the user logout, when using a local database.
func (LocalDeauthenticator) Logout ¶
func (l LocalDeauthenticator) Logout(c echo.Context) error
Logout logs out the user with the local database.
type LocalRegistrator ¶
type LocalRegistrator struct{}
LocalRegistrator is an interface for the user registration, when using a local database.
func (LocalRegistrator) Register ¶
func (l LocalRegistrator) Register(c echo.Context) error
Register logs in the user with the local database.
type Registrator ¶
type Registrator interface { // Register registers the user Register(c echo.Context) error }
Registrator is the interface that wraps the basic Register method.
func NewRegistrator ¶
func NewRegistrator() (Registrator, error)
NewRegistrator returns a new Registrator based on the DB_TYPE environment variable.
type SettingsHandler ¶
type SettingsHandler struct{}
SettingsHandler provides handlers for the settings route of the application.
func (SettingsHandler) HandleGetSettings ¶
func (h SettingsHandler) HandleGetSettings(c echo.Context) error
HandleGetSettings responds to GET on the /settings route by rendering the settings page.
type SupabaseAuthenticator ¶
type SupabaseAuthenticator struct{}
SupabaseAuthenticator is an interface for the user login, when using a remote Supabase database.
func (SupabaseAuthenticator) Login ¶
func (s SupabaseAuthenticator) Login(c echo.Context) error
Login logs in the user with the remote Supabase database.
type SupabaseRegistrator ¶
type SupabaseRegistrator struct{}
SupabaseRegistrator is an interface for the user registration, when using a remote Supabase database.
func (SupabaseRegistrator) Register ¶
func (s SupabaseRegistrator) Register(c echo.Context) error
Register logs in the user with the remote Supabase database.
type SupabaseVerifier ¶
type SupabaseVerifier struct{}
SupabaseVerifier is a struct for the user verification, when using a remote Supabase database.
func (SupabaseVerifier) Verify ¶
func (s SupabaseVerifier) Verify(c echo.Context) error
Verify verifies the user with the remote Supabase database.