multisession

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatExpiresIn added in v0.0.3

func FormatExpiresIn(t time.Time) string

FormatExpiresIn formats time until expiration

func FormatRelativeTime added in v0.0.3

func FormatRelativeTime(t time.Time) string

FormatRelativeTime formats a time as relative time (e.g., "2 hours ago")

func IsSessionActive added in v0.0.3

func IsSessionActive(expiresAt time.Time) bool

IsSessionActive checks if a session is currently active

func IsSessionExpiringSoon added in v0.0.3

func IsSessionExpiringSoon(expiresAt time.Time, within time.Duration) bool

IsSessionExpiringSoon checks if session expires within given duration

Types

type Config

type Config struct {
	// MaxSessionsPerUser is the maximum concurrent sessions per user
	MaxSessionsPerUser int `json:"maxSessionsPerUser"`
	// EnableDeviceTracking enables device fingerprinting
	EnableDeviceTracking bool `json:"enableDeviceTracking"`
	// SessionExpiry is the session expiry time in hours
	SessionExpiryHours int `json:"sessionExpiryHours"`
	// AllowCrossPlatform allows sessions across different platforms
	AllowCrossPlatform bool `json:"allowCrossPlatform"`
}

Config holds the multisession plugin configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default multisession plugin configuration

type DashboardExtension

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

DashboardExtension implements the ui.DashboardExtension interface This allows the multisession plugin to add its own screens to the dashboard

func NewDashboardExtension

func NewDashboardExtension(plugin *Plugin) *DashboardExtension

NewDashboardExtension creates a new dashboard extension for multisession

func (*DashboardExtension) DashboardWidgets

func (e *DashboardExtension) DashboardWidgets() []ui.DashboardWidget

DashboardWidgets returns widgets to show on the main dashboard

func (*DashboardExtension) ExtensionID

func (e *DashboardExtension) ExtensionID() string

ExtensionID returns the unique identifier for this extension

func (*DashboardExtension) NavigationItems

func (e *DashboardExtension) NavigationItems() []ui.NavigationItem

NavigationItems returns navigation items to register

func (*DashboardExtension) RenderDashboardWidget

func (e *DashboardExtension) RenderDashboardWidget(basePath string, currentApp *app.App) g.Node

RenderDashboardWidget renders the dashboard widget showing session stats

func (*DashboardExtension) RevokeAllUserSessions

func (e *DashboardExtension) RevokeAllUserSessions(c forge.Context) error

RevokeAllUserSessions handles revoking all sessions for a user

func (*DashboardExtension) RevokeSession

func (e *DashboardExtension) RevokeSession(c forge.Context) error

RevokeSession handles session revocation

func (*DashboardExtension) Routes

func (e *DashboardExtension) Routes() []ui.Route

Routes returns routes to register under /dashboard/app/:appId/

func (*DashboardExtension) SaveSettings

func (e *DashboardExtension) SaveSettings(c forge.Context) error

SaveSettings handles saving multisession settings

func (*DashboardExtension) ServeMultiSessionPage

func (e *DashboardExtension) ServeMultiSessionPage(c forge.Context) error

ServeMultiSessionPage renders the multi-session management page with dashboard layout

func (*DashboardExtension) ServeSessionDetailPage added in v0.0.3

func (e *DashboardExtension) ServeSessionDetailPage(c forge.Context) error

ServeSessionDetailPage renders detailed information about a single session

func (*DashboardExtension) ServeSettings

func (e *DashboardExtension) ServeSettings(c forge.Context) error

ServeSettings renders the multisession settings page

func (*DashboardExtension) ServeUserSessionsPage added in v0.0.3

func (e *DashboardExtension) ServeUserSessionsPage(c forge.Context) error

ServeUserSessionsPage renders all sessions for a specific user

func (*DashboardExtension) SetRegistry

func (e *DashboardExtension) SetRegistry(registry *dashboard.ExtensionRegistry)

SetRegistry sets the extension registry reference (called by dashboard after registration)

func (*DashboardExtension) SettingsPages

func (e *DashboardExtension) SettingsPages() []ui.SettingsPage

SettingsPages returns full settings pages for the new sidebar layout

func (*DashboardExtension) SettingsSections

func (e *DashboardExtension) SettingsSections() []ui.SettingsSection

SettingsSections returns settings sections to add to the settings page Deprecated: Use SettingsPages() instead

type DeviceInfo added in v0.0.3

type DeviceInfo struct {
	DeviceType string // Desktop, Mobile, Tablet, Bot, Unknown
	OS         string // Windows, macOS, Linux, iOS, Android, ChromeOS, etc.
	OSVersion  string // OS version if available
	Browser    string // Chrome, Firefox, Safari, Edge, etc.
	BrowserVer string // Browser version if available
	IsMobile   bool
	IsTablet   bool
	IsDesktop  bool
	IsBot      bool
}

DeviceInfo contains parsed device information from user agent

func ParseUserAgent added in v0.0.3

func ParseUserAgent(ua string) *DeviceInfo

ParseUserAgent parses a user agent string and extracts device information

func (*DeviceInfo) FormatDeviceInfo added in v0.0.3

func (d *DeviceInfo) FormatDeviceInfo() string

FormatDeviceInfo returns a human-readable device string

func (*DeviceInfo) ShortDeviceInfo added in v0.0.3

func (d *DeviceInfo) ShortDeviceInfo() string

ShortDeviceInfo returns a compact device string

type ErrorResponse

type ErrorResponse = responses.ErrorResponse

Response types - use shared responses from core

type Handler

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

func NewHandler

func NewHandler(s *Service) *Handler

func (*Handler) Delete

func (h *Handler) Delete(c forge.Context) error

Delete revokes a session by id for the current user

func (*Handler) List

func (h *Handler) List(c forge.Context) error

List returns sessions for the current user based on cookie

func (*Handler) SetActive

func (h *Handler) SetActive(c forge.Context) error

SetActive switches the current session cookie to the provided session id

type MessageResponse

type MessageResponse = responses.MessageResponse

type MultiSessionDeleteResponse

type MultiSessionDeleteResponse struct {
	Status string `json:"status" example:"deleted"`
}

type MultiSessionErrorResponse

type MultiSessionErrorResponse struct {
	Error string `json:"error" example:"Error message"`
}

Response types for multi-session routes

type MultiSessionListResponse

type MultiSessionListResponse struct {
	Sessions []interface{} `json:"sessions"`
}

type MultiSessionSetActiveResponse

type MultiSessionSetActiveResponse struct {
	Session interface{} `json:"session"`
	Token   string      `json:"token" example:"session_token_abc123"`
}

type Plugin

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

Plugin wires the multi-session service and registers routes

func NewPlugin

func NewPlugin(opts ...PluginOption) *Plugin

NewPlugin creates a new multisession plugin instance with optional configuration

func (*Plugin) DashboardExtension

func (p *Plugin) DashboardExtension() ui.DashboardExtension

DashboardExtension implements the PluginWithDashboardExtension interface This allows the multisession plugin to extend the dashboard with custom screens

func (*Plugin) GetAuthService

func (p *Plugin) GetAuthService() *auth.Service

GetAuthService returns the auth service for testing

func (*Plugin) ID

func (p *Plugin) ID() string

func (*Plugin) Init

func (p *Plugin) Init(authInst core.Authsome) error

Init accepts auth instance with GetDB method

func (*Plugin) Migrate

func (p *Plugin) Migrate() error

func (*Plugin) RegisterHooks

func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error

func (*Plugin) RegisterRoutes

func (p *Plugin) RegisterRoutes(router forge.Router) error

RegisterRoutes mounts endpoints under /api/auth/multi-session

func (*Plugin) RegisterServiceDecorators

func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error

type PluginOption

type PluginOption func(*Plugin)

PluginOption is a functional option for configuring the multisession plugin

func WithAllowCrossPlatform

func WithAllowCrossPlatform(allow bool) PluginOption

WithAllowCrossPlatform sets whether cross-platform sessions are allowed

func WithDefaultConfig

func WithDefaultConfig(cfg Config) PluginOption

WithDefaultConfig sets the default configuration for the plugin

func WithEnableDeviceTracking

func WithEnableDeviceTracking(enable bool) PluginOption

WithEnableDeviceTracking sets whether device tracking is enabled

func WithMaxSessionsPerUser

func WithMaxSessionsPerUser(max int) PluginOption

WithMaxSessionsPerUser sets the maximum concurrent sessions per user

func WithSessionExpiryHours

func WithSessionExpiryHours(hours int) PluginOption

WithSessionExpiryHours sets the session expiry time

type Service

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

Service provides multi-session operations

func NewService

func NewService(sr session.Repository, sessionSvc session.ServiceInterface, dr dev.Repository, a *auth.Service, _ interface{}) *Service

func (*Service) CurrentUserFromToken

func (s *Service) CurrentUserFromToken(ctx context.Context, token string) (xid.ID, error)

CurrentUserFromToken validates token and returns userID

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, userID, id xid.ID) error

Delete revokes a session by id ensuring ownership

func (*Service) Find

func (s *Service) Find(ctx context.Context, userID xid.ID, id xid.ID) (*session.Session, error)

Find returns a specific session by ID ensuring ownership

func (*Service) List

func (s *Service) List(ctx context.Context, userID xid.ID) (*session.ListSessionsResponse, error)

List returns all sessions for a user

type SessionTokenResponse

type SessionTokenResponse struct {
	Session interface{} `json:"session"`
	Token   string      `json:"token"`
}

type SessionsResponse

type SessionsResponse struct {
	Sessions interface{} `json:"sessions"`
}

type StatusResponse

type StatusResponse = responses.StatusResponse

Jump to

Keyboard shortcuts

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