fix(users): err is nil if token is expired in checking token failure
This commit is contained in:
parent
1c68b130f2
commit
a922ff30fc
1 changed files with 8 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
package multiusers
|
package multiusers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -8,10 +9,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
q "github.com/ihexxa/quickshare/src/handlers"
|
|
||||||
"github.com/ihexxa/quickshare/src/db/userstore"
|
"github.com/ihexxa/quickshare/src/db/userstore"
|
||||||
|
q "github.com/ihexxa/quickshare/src/handlers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrExpired = errors.New("token is expired")
|
||||||
|
|
||||||
func apiRuleCname(role, method, path string) string {
|
func apiRuleCname(role, method, path string) string {
|
||||||
return fmt.Sprintf("%s-%s-%s", role, method, path)
|
return fmt.Sprintf("%s-%s-%s", role, method, path)
|
||||||
}
|
}
|
||||||
|
@ -43,9 +46,12 @@ func (h *MultiUsersSvc) AuthN() gin.HandlerFunc {
|
||||||
|
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
expire, err := strconv.ParseInt(claims[q.ExpireParam], 10, 64)
|
expire, err := strconv.ParseInt(claims[q.ExpireParam], 10, 64)
|
||||||
if err != nil || expire <= now {
|
if err != nil {
|
||||||
c.AbortWithStatusJSON(q.ErrResp(c, 401, err))
|
c.AbortWithStatusJSON(q.ErrResp(c, 401, err))
|
||||||
return
|
return
|
||||||
|
} else if expire <= now {
|
||||||
|
c.AbortWithStatusJSON(q.ErrResp(c, 401, ErrExpired))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set default values if token is empty
|
// set default values if token is empty
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue