add login register and fix jwt
parent
2a6784802c
commit
80996966bb
@ -0,0 +1,14 @@
|
||||
package exception
|
||||
|
||||
import (
|
||||
"github.com/ajikamaludin/go-fiber-rest/pkg/utils/constants"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func ExceptionNotFound(c *fiber.Ctx, err error) error {
|
||||
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
|
||||
"status": constants.STATUS_FAIL,
|
||||
"message": "Not Found",
|
||||
"err": err.Error(),
|
||||
})
|
||||
}
|
@ -1 +0,0 @@
|
||||
package middleware
|
@ -1,19 +1,14 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Note struct {
|
||||
gorm.Model
|
||||
User_id string
|
||||
Title string `validate:"required,min=3"`
|
||||
Note string `validate:"required,min=3"`
|
||||
Tag string
|
||||
}
|
||||
|
||||
func (note Note) MarshalBinary() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf("%v-%v", note.Title, note.Note)), nil
|
||||
UserId uuid.UUID
|
||||
Title string `validate:"required,min=3"`
|
||||
Note string `validate:"required,min=3"`
|
||||
Tag string
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package jwtmanager
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/ajikamaludin/go-fiber-rest/app/configs"
|
||||
"github.com/ajikamaludin/go-fiber-rest/app/models"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
)
|
||||
|
||||
func CreateToken(user *models.User) string {
|
||||
configs := configs.GetInstance()
|
||||
|
||||
claims := jwt.MapClaims{
|
||||
"user_id": user.ID,
|
||||
"exp": time.Now().Add(time.Duration(configs.Jwtconfig.Expired) * time.Second).Unix(),
|
||||
}
|
||||
|
||||
unsignToken := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
|
||||
token, _ := unsignToken.SignedString([]byte(configs.Jwtconfig.Secret))
|
||||
|
||||
return token
|
||||
}
|
Loading…
Reference in New Issue