add the id of the user into the token
This commit is contained in:
parent
73e958efb1
commit
f914c62d5d
@ -45,7 +45,7 @@ func Login(writer http.ResponseWriter, request *http.Request, params httprouter.
|
|||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenString, err := utils.GenerateJWT(user.Email, user.Username)
|
tokenString, err := utils.GenerateJWT(user.ID, user.Email, user.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.JSONErrorOutput(writer, http.StatusBadRequest, err.Error())
|
utils.JSONErrorOutput(writer, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
|
@ -9,14 +9,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type JWTClaim struct {
|
type JWTClaim struct {
|
||||||
|
Id uint64 `json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
jwt.RegisteredClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateJWT(email string, username string) (tokenString string, err error) {
|
func GenerateJWT(id uint64, email string, username string) (tokenString string, err error) {
|
||||||
expirationTime := time.Now().Add(24 * time.Hour)
|
expirationTime := time.Now().Add(24 * time.Hour)
|
||||||
claims := &JWTClaim{
|
claims := &JWTClaim{
|
||||||
|
Id: id,
|
||||||
Email: email,
|
Email: email,
|
||||||
Username: username,
|
Username: username,
|
||||||
RegisteredClaims: jwt.RegisteredClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
|
Loading…
Reference in New Issue
Block a user