Documentation
¶
Index ¶
- Constants
- func ErrorResponse(w http.ResponseWriter, code int, message string)
- func NewAuthHandler(service *auth.Service, cookieManager *CookieManager) http.Handler
- func SuccessResponse(w http.ResponseWriter, code int, data any)
- type AuthHandler
- func (h *AuthHandler) ChangeEmailHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) DeleteProfileHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) GetMeHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) RefreshTokenHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) ResetPasswordHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) SendEmailVerificationHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) SendPasswordResetHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) SignInHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) SignOutHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) SignUpHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) UpdateProfileHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) ValidateSessionHandler(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) VerifyEmailHandler(w http.ResponseWriter, r *http.Request)
- type ChangeEmailRequest
- type ChangeEmailResponse
- type CookieManager
- type DeleteProfileRequest
- type DeleteProfileResponse
- type GetMeRequest
- type GetMeResponse
- type HTTPError
- type OAuthAuthorizeRequest
- type OAuthCallbackRequest
- type OAuthHandler
- func (h *OAuthHandler) HandleOAuthAuthorize(w http.ResponseWriter, r *http.Request)
- func (h *OAuthHandler) HandleOAuthCallback(w http.ResponseWriter, r *http.Request)
- func (h *OAuthHandler) HandleOAuthLinkedAccounts(w http.ResponseWriter, r *http.Request)
- func (h *OAuthHandler) HandleOAuthUnlink(w http.ResponseWriter, r *http.Request)
- func (h *OAuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type RefreshTokenRequest
- type RefreshTokenResponse
- type RequestPasswordResetRequest
- type RequestPasswordResetResponse
- type ResetPasswordRequest
- type ResetPasswordResponse
- type Response
- type SendEmailVerificationRequest
- type SendEmailVerificationResponse
- type SignInRequest
- type SignInResponse
- type SignOutRequest
- type SignUpRequest
- type SignUpResponse
- type UpdateProfileRequest
- type UpdateProfileResponse
- type ValidateSessionRequest
- type ValidateSessionResponse
- type VerifyEmailResponse
Constants ¶
const ( // DefaultCookiePrefix is the default prefix for all cookies. DefaultCookiePrefix = "go-better-auth" // SessionCookieName is the default name for the session cookie. SessionCookieName = "session_token" )
Variables ¶
This section is empty.
Functions ¶
func ErrorResponse ¶
func ErrorResponse(w http.ResponseWriter, code int, message string)
ErrorResponse writes a JSON error response
func NewAuthHandler ¶
func NewAuthHandler(service *auth.Service, cookieManager *CookieManager) http.Handler
NewAuthHandler creates a new auth handler
func SuccessResponse ¶
func SuccessResponse(w http.ResponseWriter, code int, data any)
SuccessResponse writes a JSON success response
Types ¶
type AuthHandler ¶
type AuthHandler struct {
// contains filtered or unexported fields
}
AuthHandler implements http.Handler for all auth endpoints
func (*AuthHandler) ChangeEmailHandler ¶
func (h *AuthHandler) ChangeEmailHandler(w http.ResponseWriter, r *http.Request)
ChangeEmailHandler handles POST /auth/change-email Requires AuthMiddleware to be applied to extract user ID from context Initiates an email change by sending a verification token to the new email
func (*AuthHandler) DeleteProfileHandler ¶
func (h *AuthHandler) DeleteProfileHandler(w http.ResponseWriter, r *http.Request)
DeleteProfileHandler handles DELETE /auth/me Requires AuthMiddleware to be applied to extract user ID from context
func (*AuthHandler) GetMeHandler ¶
func (h *AuthHandler) GetMeHandler(w http.ResponseWriter, r *http.Request)
GetMeHandler handles GET /auth/me Requires AuthMiddleware to be applied to extract user ID from context
func (*AuthHandler) RefreshTokenHandler ¶
func (h *AuthHandler) RefreshTokenHandler(w http.ResponseWriter, r *http.Request)
RefreshTokenHandler handles POST /auth/refresh
func (*AuthHandler) ResetPasswordHandler ¶
func (h *AuthHandler) ResetPasswordHandler(w http.ResponseWriter, r *http.Request)
ResetPasswordHandler handles POST /auth/reset-password
func (*AuthHandler) SendEmailVerificationHandler ¶
func (h *AuthHandler) SendEmailVerificationHandler(w http.ResponseWriter, r *http.Request)
SendEmailVerificationHandler handles POST /auth/email-verification
func (*AuthHandler) SendPasswordResetHandler ¶
func (h *AuthHandler) SendPasswordResetHandler(w http.ResponseWriter, r *http.Request)
SendPasswordResetHandler handles POST /auth/password-reset
func (*AuthHandler) ServeHTTP ¶
func (h *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP dispatches requests to appropriate handlers
func (*AuthHandler) SignInHandler ¶
func (h *AuthHandler) SignInHandler(w http.ResponseWriter, r *http.Request)
SignInHandler handles POST /auth/signin
func (*AuthHandler) SignOutHandler ¶
func (h *AuthHandler) SignOutHandler(w http.ResponseWriter, r *http.Request)
SignOutHandler handles POST /auth/signout
func (*AuthHandler) SignUpHandler ¶
func (h *AuthHandler) SignUpHandler(w http.ResponseWriter, r *http.Request)
SignUpHandler handles POST /auth/signup
func (*AuthHandler) UpdateProfileHandler ¶
func (h *AuthHandler) UpdateProfileHandler(w http.ResponseWriter, r *http.Request)
UpdateProfileHandler handles PATCH /auth/me Requires AuthMiddleware to be applied to extract user ID from context
func (*AuthHandler) ValidateSessionHandler ¶
func (h *AuthHandler) ValidateSessionHandler(w http.ResponseWriter, r *http.Request)
ValidateSessionHandler handles GET /auth/validate
func (*AuthHandler) VerifyEmailHandler ¶
func (h *AuthHandler) VerifyEmailHandler(w http.ResponseWriter, r *http.Request)
VerifyEmailHandler handles GET /auth/verify-email?token={token}&callbackURL={callbackURL} OR POST /auth/verify-email This unified handler verifies all types of verification tokens: - Email verification - Email change confirmation - Password reset confirmation It extracts the token from query parameters or POST body, validates it, and redirects to a success page or returns a response.
type ChangeEmailRequest ¶
type ChangeEmailResponse ¶
type CookieManager ¶
type CookieManager struct {
// contains filtered or unexported fields
}
CookieManager handles setting and clearing cookies with configurable options.
func NewCookieManager ¶
func NewCookieManager(cfg *domain.Config) *CookieManager
NewCookieManager creates a new CookieManager based on the application configuration. It centralizes the logic for determining cookie names, security, and domain settings.
func (*CookieManager) ClearSessionCookie ¶
func (cm *CookieManager) ClearSessionCookie(w http.ResponseWriter)
ClearSessionCookie clears the session cookie using the configured settings.
func (*CookieManager) GetSessionCookieName ¶
func (cm *CookieManager) GetSessionCookieName() string
GetSessionCookieName returns the configured name for the session cookie. This is useful for middleware or other parts of the app that need to read the cookie.
func (*CookieManager) SetSessionCookie ¶
func (cm *CookieManager) SetSessionCookie(w http.ResponseWriter, token string, expiresAt time.Time)
SetSessionCookie sets the session token as a cookie using the configured settings.
type DeleteProfileRequest ¶
type DeleteProfileRequest struct {
ConfirmPassword string `json:"confirm_password"`
}
type DeleteProfileResponse ¶
type GetMeRequest ¶
type GetMeRequest struct {
UserID string `json:"user_id"`
}
type GetMeResponse ¶
type HTTPError ¶
HTTPError represents an HTTP error with status code
func InternalServerError ¶
InternalServerError creates a 500 error
func NewHTTPError ¶
NewHTTPError creates a new HTTP error
type OAuthAuthorizeRequest ¶
type OAuthAuthorizeRequest struct {
// RedirectURI is where the user should be redirected after OAuth flow completes
RedirectURI string `json:"redirect_uri"`
// State is optional additional state to preserve through the OAuth flow
State string `json:"state"`
}
OAuthAuthorizeRequest represents the query parameters for OAuth authorization
type OAuthCallbackRequest ¶
type OAuthCallbackRequest struct {
Code string `json:"code"`
State string `json:"state"`
Error string `json:"error"`
}
OAuthCallbackRequest represents the query parameters for OAuth callback
type OAuthHandler ¶
type OAuthHandler struct {
// contains filtered or unexported fields
}
OAuthHandler handles OAuth authentication endpoints
func NewOAuthHandler ¶
func NewOAuthHandler( service *auth.Service, stateManager *storage.OAuthStateManager, providerReg account.OAuthProviderRegistry, ) *OAuthHandler
NewOAuthHandler creates a new OAuth handler
func (*OAuthHandler) HandleOAuthAuthorize ¶
func (h *OAuthHandler) HandleOAuthAuthorize(w http.ResponseWriter, r *http.Request)
HandleOAuthAuthorize initiates the OAuth authorization flow GET /auth/oauth/{provider}
func (*OAuthHandler) HandleOAuthCallback ¶
func (h *OAuthHandler) HandleOAuthCallback(w http.ResponseWriter, r *http.Request)
HandleOAuthCallback handles the OAuth callback from the provider GET /auth/oauth/{provider}/callback
func (*OAuthHandler) HandleOAuthLinkedAccounts ¶
func (h *OAuthHandler) HandleOAuthLinkedAccounts(w http.ResponseWriter, r *http.Request)
HandleOAuthLinkedAccounts returns all OAuth accounts linked to the user GET /auth/oauth/accounts
func (*OAuthHandler) HandleOAuthUnlink ¶
func (h *OAuthHandler) HandleOAuthUnlink(w http.ResponseWriter, r *http.Request)
HandleOAuthUnlink unlinks an OAuth account from the user DELETE /auth/oauth/{provider}
func (*OAuthHandler) ServeHTTP ¶
func (h *OAuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler for OAuth routes
type RefreshTokenRequest ¶
type RefreshTokenRequest struct {
Token string `json:"token"`
}
type RefreshTokenResponse ¶
type RequestPasswordResetResponse ¶
type RequestPasswordResetResponse struct {
Message string `json:"message"`
}
type ResetPasswordRequest ¶
type ResetPasswordResponse ¶
type ResetPasswordResponse struct {
Message string `json:"message"`
}
type Response ¶
type Response struct {
Success bool `json:"success"`
Data any `json:"data,omitempty"`
Error string `json:"error,omitempty"`
}
Response is the standard API response envelope
type SendEmailVerificationResponse ¶
type SendEmailVerificationResponse struct {
Status bool `json:"status"`
}
type SignInRequest ¶
type SignInResponse ¶
type SignOutRequest ¶
type SignOutRequest struct {
Token string `json:"token"`
}
type SignUpRequest ¶
type SignUpResponse ¶
type UpdateProfileRequest ¶
type UpdateProfileResponse ¶
type ValidateSessionRequest ¶
type ValidateSessionRequest struct {
Token string `json:"token"`
}