55 "net/http"
66 "time"
77
8- "github.com/golang-jwt/jwt"
8+ "github.com/golang-jwt/jwt/v4 "
99 "github.com/labstack/echo/v4"
1010 "github.com/labstack/echo/v4/middleware"
1111 "github.com/mrdoob/glsl-sandbox/server/store"
@@ -18,12 +18,10 @@ const (
1818 bcryptCost = 8
1919)
2020
21- var (
22- ErrNotAuthorized = fmt .Errorf ("user not authorized" )
23- )
21+ var ErrNotAuthorized = fmt .Errorf ("user not authorized" )
2422
2523type Claims struct {
26- jwt.StandardClaims
24+ jwt.RegisteredClaims
2725
2826 Name string `json:"name"`
2927 Role store.Role `json:"role"`
@@ -49,12 +47,12 @@ func (a *Auth) GenerateToken(c echo.Context, u store.User) error {
4947 return fmt .Errorf ("invalid role" )
5048 }
5149
52- expirationTime := time .Now ().Add (tokenDuration )
50+ expirationTime := jwt . NewNumericDate ( time .Now ().Add (tokenDuration ) )
5351 claims := Claims {
5452 Name : u .Name ,
5553 Role : u .Role ,
56- StandardClaims : jwt.StandardClaims {
57- ExpiresAt : expirationTime . Unix () ,
54+ RegisteredClaims : jwt.RegisteredClaims {
55+ ExpiresAt : expirationTime ,
5856 },
5957 }
6058
@@ -68,7 +66,7 @@ func (a *Auth) GenerateToken(c echo.Context, u store.User) error {
6866 cookie := http.Cookie {
6967 Name : accessTokenCookieName ,
7068 Value : tokenString ,
71- Expires : expirationTime ,
69+ Expires : expirationTime . Time ,
7270 Path : "/" ,
7371 HttpOnly : true ,
7472 }
0 commit comments