🐛 Fix auth cache
This commit is contained in:
parent
808e7998dd
commit
40b64a3559
File diff suppressed because it is too large
Load Diff
35
.idea/workspace.xml
generated
35
.idea/workspace.xml
generated
@ -4,15 +4,13 @@
|
|||||||
<option name="autoReloadType" value="ALL" />
|
<option name="autoReloadType" value="ALL" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Authkit support check user related permission">
|
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Authkit can get user">
|
||||||
<change afterPath="$PROJECT_DIR$/pkg/authkit/user.go" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/dataSources.local.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources.local.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources/74bcf3ef-a2b9-435b-b9e5-f32902a33b25.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/notify.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/notify.go" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pkg/internal/cache/store.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/cache/store.go" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/user.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/user.go" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pkg/internal/services/auth.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/auth.go" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -54,7 +52,7 @@
|
|||||||
<component name="PropertiesComponent"><
|
cacheManager := cache.New[any](localCache.S)
|
||||||
marshal := marshaler.New(cacheManager)
|
marshal := marshaler.New(cacheManager)
|
||||||
contx := context.Background()
|
|
||||||
|
|
||||||
if val, err := marshal.Get(contx, GetAuthContextCacheKey(sessionId), new(models.AuthTicket)); err == nil {
|
key := GetAuthContextCacheKey(sessionId)
|
||||||
|
if val, err := marshal.Get(context.Background(), key, new(models.AuthTicket)); err == nil {
|
||||||
ctx = *val.(*models.AuthTicket)
|
ctx = *val.(*models.AuthTicket)
|
||||||
|
// log.Debug().Uint("session", sessionId).Msg("Hint auth context cache once")
|
||||||
} else {
|
} else {
|
||||||
ctx, err = CacheAuthContext(sessionId)
|
ctx, err = CacheAuthContext(sessionId)
|
||||||
log.Debug().Uint("session", sessionId).Msg("Created a new auth context cache")
|
log.Debug().Uint("session", sessionId).Msg("Created a new auth context cache")
|
||||||
@ -85,13 +86,13 @@ func CacheAuthContext(sessionId uint) (models.AuthTicket, error) {
|
|||||||
// Put the data into the cache
|
// Put the data into the cache
|
||||||
cacheManager := cache.New[any](localCache.S)
|
cacheManager := cache.New[any](localCache.S)
|
||||||
marshal := marshaler.New(cacheManager)
|
marshal := marshaler.New(cacheManager)
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
_ = marshal.Set(
|
key := GetAuthContextCacheKey(sessionId)
|
||||||
ctx,
|
err = marshal.Set(
|
||||||
GetAuthContextCacheKey(sessionId),
|
context.Background(),
|
||||||
|
key,
|
||||||
ticket,
|
ticket,
|
||||||
store.WithExpiration(3*time.Minute),
|
store.WithExpiration(10*time.Minute),
|
||||||
store.WithTags([]string{"auth-context", fmt.Sprintf("user#%d", user.ID)}),
|
store.WithTags([]string{"auth-context", fmt.Sprintf("user#%d", user.ID)}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user