https://github.com/kennethklee/pb-auth
Pocketbase auth library
https://github.com/kennethklee/pb-auth
pocketbase
Last synced: 3 months ago
JSON representation
Pocketbase auth library
- Host: GitHub
- URL: https://github.com/kennethklee/pb-auth
- Owner: kennethklee
- License: mit
- Created: 2022-10-11T15:04:52.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-19T15:00:23.000Z (almost 2 years ago)
- Last Synced: 2025-04-14T17:52:10.202Z (6 months ago)
- Topics: pocketbase
- Language: Go
- Homepage:
- Size: 274 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Pocketbase Auth Library
=======================Currently supports the following:
* pocketbase 0.8.0
* Header Auth
* `/api/me` endpoint for current userInstallation
------------```
go get github.com/kennethklee/pb-auth
```Usage
-----```go
package mainimport (
"fmt"
"os""github.com/fatih/color"
"github.com/kennethklee/pb-auth"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/core"
)func main() {
pb := pocketbase.New()pb.OnBeforeServe().Add(func(e *core.ServeEvent) error {
bold := color.New(color.Bold).Add(color.FgGreen)
bold.Println("> Auth Config")
headerAuthConfig := getHeaderAuthConfig()
if headerAuthConfig.IsValid() {
fmt.Println(" - Header auth enabled")
} else {
fmt.Println(" - Header auth disabled")
}auth.InstallHeaderAuth(e.App, e.Router, headerAuthConfig)
auth.InstallAPIMeEndpoint(e.Router)return nil
})pb.Start()
}func getHeaderAuthConfig() auth.HeaderAuthConfig {
headerAuthConfig := auth.HeaderAuthConfig{
EmailHeader: "X-Auth-Email",
NameHeader: "X-Auth-Name",
AutoCreateUser: true,
}// when not running `APP_ENV=production`, only local, force email and name
if os.Getenv("APP_ENV") != "production" {
headerAuthConfig.ForceEmail = "local@mycompany.com"
headerAuthConfig.ForceName = "Local User"
}return headerAuthConfig
}
```