Add admin user, and an option to add a user admin on startup

This commit is contained in:
2026-04-28 19:50:35 +02:00
parent d5281e7d57
commit ff8604eac1
11 changed files with 144 additions and 52 deletions

View File

@@ -1,10 +1,12 @@
package jwtauth
import (
"strconv"
"github.com/golang-jwt/jwt/v5"
)
func GenerateJwtToken(username string) (string, error) {
func GenerateJwtToken(username string, admin bool) (string, error) {
var s string
key, err := GetJwtKey()
if err != nil {
@@ -12,8 +14,9 @@ func GenerateJwtToken(username string) (string, error) {
}
t := jwt.NewWithClaims(jwt.SigningMethodHS256,
jwt.MapClaims{
"iss": "bibliomane",
"sub": username,
"iss": "bibliomane",
"sub": username,
"admin": strconv.FormatBool(admin),
})
return t.SignedString(key)
}