Documentation
¶
Index ¶
- Constants
- func UserFromContext(ctx context.Context) *models.User
- type Auth
- func (a *Auth) AuthMiddleware(next http.Handler) http.Handler
- func (a *Auth) Authenticate(ctx context.Context, email, password string) (*models.User, error)
- func (a *Auth) ClearTokenCookie(w http.ResponseWriter)
- func (a *Auth) GenerateToken(userID int) (string, error)
- func (a *Auth) RequireAuth(next http.Handler) http.Handler
- func (a *Auth) SetTokenCookie(w http.ResponseWriter, token string)
- func (a *Auth) ValidateToken(tokenString string) (int, error)
- type Claims
Constants ¶
View Source
const ( // TokenCookieName is the name of the cookie used to store the auth token TokenCookieName = "friday_talks_auth_token" // TokenExpiry is the duration after which a token will expire TokenExpiry = 24 * time.Hour // ContextUserKey is the key used to store user info in request context ContextUserKey = "user" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth handles authentication and authorization
func NewAuth ¶
func NewAuth(jwtSecret string, userRepo models.UserRepository) *Auth
NewAuth creates a new Auth instance
func (*Auth) AuthMiddleware ¶
AuthMiddleware creates middleware that validates JWT tokens and adds user to context
func (*Auth) Authenticate ¶
Authenticate checks if the provided credentials are valid
func (*Auth) ClearTokenCookie ¶
func (a *Auth) ClearTokenCookie(w http.ResponseWriter)
ClearTokenCookie clears the authentication token cookie
func (*Auth) GenerateToken ¶
GenerateToken creates a new JWT token for the given user
func (*Auth) RequireAuth ¶
RequireAuth creates middleware that requires authentication
func (*Auth) SetTokenCookie ¶
func (a *Auth) SetTokenCookie(w http.ResponseWriter, token string)
SetTokenCookie sets the authentication token as a cookie
Click to show internal directories.
Click to hide internal directories.