kuta

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 6 Imported by: 2

README

Kuta 🏰

kuta [kú.tâ.]: fortress (n.) — in Bisaya/Visayan

Simple, secure authentication framework for Go.

Greatly inspired by Better Auth.

Installation

go get github.com/lborres/kuta

Usage

Setup

Insert the following block in your main file after initializing your app and storage.

import (
  "github.com/lborres/kuta"
  fiberadapter "github.com/lborres/kuta/adapters/fiber"
  pgxadapter "github.com/lborres/kuta/adapters/pgx"
)

func main() {
  // ...your existing code

  k, err = kuta.New(kuta.Config{
    Secret: "mysupersecretsecret",

    Database:      pgxadapter.New(pool),
    HTTP:          fiberadapter.New(app),
    SessionConfig: &kuta.SessionConfig{MaxAge: 24 * time.Hour},
  })
  if err != nil {
    log.Fatalf("could not create kuta instance: %v", err)
  }

  // ...your existing code
}

That's it! You're good to go!

You can now protect your endpoints:

app.Get("/sensitive", k.Protected, SensitiveDataHandler)

The following endpoints are now available to you:

POST /api/auth/sign-in # Email/password login, returns session token
POST /api/auth/sign-up # User registration
POST /api/auth/sign-out # Destroy current session
GET /api/auth/session # Get current session info (verify token, return user data)
POST /api/auth/refresh # Refresh session token (extend expiry)

See examples to learn more.

Credits

Inspired by Better Auth - bringing the same developer experience to Go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserExists          = core.ErrUserExists
	ErrUserNotFound        = core.ErrUserNotFound
	ErrInvalidCredentials  = core.ErrInvalidCredentials
	ErrMissingAuthHeader   = core.ErrMissingAuthHeader
	ErrInvalidToken        = core.ErrInvalidToken
	ErrSessionNotFound     = core.ErrSessionNotFound
	ErrSessionExpired      = core.ErrSessionExpired
	ErrCacheNotFound       = core.ErrCacheNotFound
	ErrInvalidAuthHeader   = core.ErrInvalidAuthHeader
	ErrEmailRequired       = core.ErrEmailRequired
	ErrPasswordRequired    = core.ErrPasswordRequired
	ErrPasswordTooShort    = core.ErrPasswordTooShort
	ErrPasswordTooLong     = core.ErrPasswordTooLong
	ErrPasswordComplexity  = core.ErrPasswordComplexity
	ErrInvalidEmail        = core.ErrInvalidEmail
	ErrDBAdapterRequired   = core.ErrDBAdapterRequired
	ErrHTTPAdapterRequired = core.ErrHTTPAdapterRequired
	ErrSecretRequired      = core.ErrSecretRequired
	ErrSecretTooShort      = core.ErrSecretTooShort
	ErrNotImplemented      = core.ErrNotImplemented
	ErrInvalidRequestBody  = core.ErrInvalidRequestBody
)

Errors

View Source
var (
	NewInMemoryCache = cache.NewInMemoryCache
	NewArgon2        = crypto.NewArgon2
)

Constructors

Functions

This section is empty.

Types

type Account

type Account = core.Account

Re-exports from core and services packages

type AuthProvider

type AuthProvider = core.AuthProvider

Re-exports from core and services packages

type Cache

type Cache = core.Cache

Re-exports from core and services packages

type CacheConfig

type CacheConfig = core.CacheConfig

Re-exports from core and services packages

type CacheStats

type CacheStats = core.CacheStats

Re-exports from core and services packages

type Config

type Config struct {
	Secret          string
	Database        StorageProvider
	HTTP            HTTPProvider
	Plugins         []Plugin
	SessionConfig   *SessionConfig
	CookieConfig    *CookieConfig
	PasswordHandler PasswordHandler
	BasePath        string
	CacheProvider   Cache
	DisableCache    bool
}

Config for Kuta initialization

type CookieConfig added in v0.1.2

type CookieConfig = core.CookieConfig

Re-exports from core and services packages

type Endpoint

type Endpoint = core.Endpoint

Re-exports from core and services packages

type EndpointMetadata

type EndpointMetadata = core.EndpointMetadata

Re-exports from core and services packages

type EndpointProvider

type EndpointProvider = core.EndpointProvider

Re-exports from core and services packages

type ErrorResponse

type ErrorResponse = core.ErrorResponse

Re-exports from core and services packages

type HTTPProvider

type HTTPProvider = core.HTTPProvider

Re-exports from core and services packages

type Kuta

type Kuta struct {
	Protected any
	// contains filtered or unexported fields
}

Kuta is the main auth instance

func New

func New(config Config) (*Kuta, error)

New creates a new Kuta instance

type PasswordHandler

type PasswordHandler = crypto.PasswordHandler

Re-exports from core and services packages

type Plugin added in v0.1.3

type Plugin = core.Plugin

Re-exports from core and services packages

type PluginDependencies added in v0.1.3

type PluginDependencies = core.PluginDependencies

Re-exports from core and services packages

type PluginEndpoint added in v0.1.3

type PluginEndpoint = core.PluginEndpoint

Re-exports from core and services packages

type RefreshResult

type RefreshResult = core.RefreshResult

Re-exports from core and services packages

type RequestContext

type RequestContext = core.RequestContext

Re-exports from core and services packages

type Session

type Session = core.Session

Re-exports from core and services packages

type SessionConfig

type SessionConfig = core.SessionConfig

Re-exports from core and services packages

type SessionData

type SessionData = core.SessionData

Re-exports from core and services packages

type SignInInput

type SignInInput = core.SignInInput

Re-exports from core and services packages

type SignInResult

type SignInResult = core.SignInResult

Re-exports from core and services packages

type SignUpInput

type SignUpInput = core.SignUpInput

Re-exports from core and services packages

type SignUpResult

type SignUpResult = core.SignUpResult

Re-exports from core and services packages

type StorageProvider

type StorageProvider = core.StorageProvider

Re-exports from core and services packages

type User

type User = core.User

Re-exports from core and services packages

Directories

Path Synopsis
adapters
pgx
pkg
plugins
admin
Package admin provides admin functionality for Kuta authentication.
Package admin provides admin functionality for Kuta authentication.

Jump to

Keyboard shortcuts

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