Skip to content

Commit

Permalink
chore(ctxkeys): rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviofernandes004 committed Oct 25, 2024
1 parent d56cede commit cbe37a8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
9 changes: 0 additions & 9 deletions internal/ctx_env/ctx_env.go

This file was deleted.

9 changes: 9 additions & 0 deletions internal/ctxkeys/ctxkeys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ctxkeys

// Keys used for storing/retrieving user information in the context of a request after authentication.
type UserIDKey struct{}
type UsernameKey struct{}
type VarsKey struct{}
type ExpiryKey struct{}
type TokenIDKey struct{}
type TokenIssuedAtKey struct{}
8 changes: 4 additions & 4 deletions internal/satori/satori.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

"github.com/golang-jwt/jwt/v4"
"github.com/heroiclabs/nakama-common/runtime"
"github.com/heroiclabs/nakama/v3/internal/ctx_env"
"github.com/heroiclabs/nakama/v3/internal/ctxkeys"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -122,9 +122,9 @@ func (stc *sessionTokenClaims) Valid() error {
}

func (s *SatoriClient) generateToken(ctx context.Context, id string) (string, error) {
tid, _ := ctx.Value(ctx_env.CtxTokenIDKey{}).(string)
tIssuedAt, _ := ctx.Value(ctx_env.CtxTokenIssuedAtKey{}).(int64)
tExpirySec, _ := ctx.Value(ctx_env.CtxExpiryKey{}).(int64)
tid, _ := ctx.Value(ctxkeys.TokenIDKey{}).(string)
tIssuedAt, _ := ctx.Value(ctxkeys.TokenIssuedAtKey{}).(int64)
tExpirySec, _ := ctx.Value(ctxkeys.ExpiryKey{}).(int64)

timestamp := time.Now().UTC()
if tIssuedAt == 0 && tExpirySec > s.nakamaTokenExpirySec {
Expand Down
14 changes: 7 additions & 7 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
grpcgw "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/heroiclabs/nakama-common/api"
"github.com/heroiclabs/nakama/v3/apigrpc"
"github.com/heroiclabs/nakama/v3/internal/ctx_env"
"github.com/heroiclabs/nakama/v3/internal/ctxkeys"
"github.com/heroiclabs/nakama/v3/social"
"go.uber.org/zap"
"google.golang.org/grpc"
Expand All @@ -61,12 +61,12 @@ var once sync.Once
const byteBracket byte = '{'

// Keys used for storing/retrieving user information in the context of a request after authentication.
type ctxUserIDKey = ctx_env.CtxUserIDKey
type ctxUsernameKey = ctx_env.CtxUsernameKey
type ctxVarsKey = ctx_env.CtxVarsKey
type ctxExpiryKey = ctx_env.CtxExpiryKey
type ctxTokenIDKey = ctx_env.CtxTokenIDKey
type ctxTokenIssuedAtKey = ctx_env.CtxTokenIssuedAtKey
type ctxUserIDKey = ctxkeys.UserIDKey
type ctxUsernameKey = ctxkeys.UsernameKey
type ctxVarsKey = ctxkeys.VarsKey
type ctxExpiryKey = ctxkeys.ExpiryKey
type ctxTokenIDKey = ctxkeys.TokenIDKey
type ctxTokenIssuedAtKey = ctxkeys.TokenIssuedAtKey

type ctxFullMethodKey struct{}

Expand Down

0 comments on commit cbe37a8

Please sign in to comment.