pomme/internal/api/jwt.go

24 lines
400 B
Go

package api
import (
"log"
"github.com/go-chi/jwtauth/v5"
)
var tokenAuth *jwtauth.JWTAuth
const secret = "piss"
func init() {
tokenAuth = jwtauth.New("HS256", []byte(secret), nil)
}
func makeToken(username string) string {
_, tokenString, err := tokenAuth.Encode(map[string]interface{}{"username": username, "admin": "false"})
if err != nil {
log.Fatalln(err)
}
return tokenString
}