Skip to content

Commit

Permalink
change user id type
Browse files Browse the repository at this point in the history
  • Loading branch information
krabiworld committed Aug 21, 2024
1 parent dcd5d39 commit b97a90d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type response struct {
User int `json:"user"`
User uint64 `json:"user"`
}

type Auth struct {
Expand Down Expand Up @@ -199,7 +199,7 @@ func (a *Auth) IsAdmin(next fasthttp.RequestHandler) fasthttp.RequestHandler {

ctx.SetUserValue("user", id)
} else {
ctx.SetUserValue("user", 0)
ctx.SetUserValue("user", uint64(0))
}

next(ctx)
Expand All @@ -215,13 +215,13 @@ func (a *Auth) IsAdminFiber(c *fiber.Ctx) error {

c.Locals("user", id)
} else {
c.Locals("user", 0)
c.Locals("user", uint64(0))
}

return c.Next()
}

func VerifyAdmin(ctx *fasthttp.RequestCtx, host string) (int, error) {
func VerifyAdmin(ctx *fasthttp.RequestCtx, host string) (uint64, error) {
token := string(ctx.Request.Header.Peek("Authorization"))
if validator.IsEmpty(token) {
return 0, errors.New("bearer token required")
Expand All @@ -230,7 +230,7 @@ func VerifyAdmin(ctx *fasthttp.RequestCtx, host string) (int, error) {
return internalVerifyAdmin(token, host)
}

func VerifyUserFiber(c *fiber.Ctx, host string) (int, error) {
func VerifyUserFiber(c *fiber.Ctx, host string) (uint64, error) {
token := c.Get("Authorization")
if validator.IsEmpty(token) {
return 0, errors.New("bearer token required")
Expand All @@ -239,7 +239,7 @@ func VerifyUserFiber(c *fiber.Ctx, host string) (int, error) {
return internalVerifyUser(token, host)
}

func VerifyAdminFiber(c *fiber.Ctx, host string) (int, error) {
func VerifyAdminFiber(c *fiber.Ctx, host string) (uint64, error) {
token := c.Get("Authorization")
if validator.IsEmpty(token) {
return 0, errors.New("bearer token required")
Expand Down Expand Up @@ -278,7 +278,7 @@ func internalGetPermissions(token, host string) (perms TotalAdminPermission, err
return r, nil
}

func internalVerifyUser(token, host string) (int, error) {
func internalVerifyUser(token, host string) (uint64, error) {
req, err := http.NewRequest("POST", host+"/verifyUser", nil)
if err != nil {
return 0, errors.New("http request making error: " + err.Error())
Expand Down Expand Up @@ -308,7 +308,7 @@ func internalVerifyUser(token, host string) (int, error) {
return r.User, nil
}

func internalVerifyAdmin(token, host string) (int, error) {
func internalVerifyAdmin(token, host string) (uint64, error) {
req, err := http.NewRequest("POST", host+"/verifyAdmin", nil)
if err != nil {
return 0, errors.New("http request making error: " + err.Error())
Expand Down
2 changes: 1 addition & 1 deletion middlewares/fiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func VerifyUser(c *fiber.Ctx) error {

c.Locals("user", id)
} else {
c.Locals("user", 0)
c.Locals("user", uint64(0))
}

return c.Next()
Expand Down

0 comments on commit b97a90d

Please sign in to comment.