lastlogin

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 7 Imported by: 0

README

GoModularAuth LastLogin Plugin (gomodularauth-lastlogin)

Go Reference

The LastLogin Plugin tracks and records user authentication activity, timestamps, authentication methods, and originating IP/User-Agent metadata.

Installation

go get github.com/BladiCreator/go-modular-auth/plugins/lastlogin

Quick Start

package main

import (
	"context"
	"time"

	auth "github.com/BladiCreator/go-modular-auth"
	adaptermem "github.com/BladiCreator/go-modular-auth/adapters/memory"
	"github.com/BladiCreator/go-modular-auth/plugins/lastlogin"
)

func main() {
	ctx := context.Background()

	engine, _ := auth.New(auth.Config{
		Adapter: adaptermem.NewAdapter(),
		Plugins: []auth.PluginModule{lastlogin.New()},
	})

	tracker, _ := auth.Get[lastlogin.LastLogin](engine)

	// Record authentication activity
	_ = tracker.Record(ctx, &lastlogin.Record{
		UserID:     "usr_alice",
		Method:     "password",
		IP:         "192.0.2.1",
		UserAgent:  "Mozilla/5.0",
		LoggedInAt: time.Now().UTC(),
	})

	// Query last login details
	rec, _ := tracker.Get(ctx, "usr_alice")
	_ = rec
}

Detailed guide: doc/plugins/lastlogin.md.

Documentation

Overview

Package lastlogin provides last login tracking capabilities (reserved module).

Index

Constants

View Source
const (
	ModelLastLogins = "last_logins"
)
View Source
const PluginID = "lastlogin"

Variables

View Source
var (
	ErrNotFound      = errors.New("lastlogin: record not found")
	ErrInvalidUserID = errors.New("lastlogin: user_id is required")
	ErrInvalidMethod = errors.New("lastlogin: auth method is required")
)

Functions

func RegisterSchema

func RegisterSchema(s *schema.Schema) error

RegisterSchema registers the last_logins model with the unified schema.

Types

type Config

type Config struct{}

Config holds configuration parameters for the lastlogin plugin.

type LastLogin

type LastLogin interface {
	Record(ctx context.Context, rec *Record) error
	Get(ctx context.Context, userID string) (*Record, error)
}

LastLogin defines the service capability to track and query authentication history.

type Module

type Module struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Module

func (*Module) ID

func (m *Module) ID() string

func (*Module) Init

func (m *Module) Init(h *auth.Host) error

func (*Module) RegisterSchema

func (m *Module) RegisterSchema(s *schema.Schema) error

type Option

type Option func(*Config)

Option configures the lastlogin module.

type Record

type Record struct {
	UserID     string    `json:"user_id"`
	AccountID  string    `json:"account_id,omitempty"`
	Method     string    `json:"method"`
	IP         string    `json:"ip,omitempty"`
	UserAgent  string    `json:"user_agent,omitempty"`
	LoggedInAt time.Time `json:"logged_in_at"`
}

Record captures metadata of a user's latest authentication.

Jump to

Keyboard shortcuts

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