mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
29 lines
653 B
Go
29 lines
653 B
Go
package middleware
|
|
|
|
import (
|
|
"github.com/zap-proto/zip"
|
|
|
|
"github.com/hanzoai/commerce/auth"
|
|
"github.com/hanzoai/commerce/config"
|
|
"github.com/hanzoai/commerce/log"
|
|
"github.com/hanzoai/commerce/models/user"
|
|
"github.com/hanzoai/commerce/util/session"
|
|
)
|
|
|
|
func AcquireUser(moduleName string) zip.Handler {
|
|
return func(c *zip.Ctx) error {
|
|
u, err := auth.GetCurrentUser(c)
|
|
if err != nil {
|
|
log.Warn("Unable to acquire user.", c)
|
|
session.Clear(c)
|
|
return c.Redirect(302, config.UrlFor(moduleName, "/login"))
|
|
}
|
|
c.Locals("user", u)
|
|
return c.Next()
|
|
}
|
|
}
|
|
|
|
func GetCurrentUser(c *zip.Ctx) *user.User {
|
|
return c.Locals("user").(*user.User)
|
|
}
|