mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 13:53:41 +03:00
23 lines
492 B
Go
23 lines
492 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"lunar-tear/server/internal/store"
|
|
|
|
"google.golang.org/grpc/metadata"
|
|
)
|
|
|
|
func CurrentUserId(ctx context.Context, users store.UserRepository, sessions store.SessionRepository) int64 {
|
|
if md, ok := metadata.FromIncomingContext(ctx); ok {
|
|
if vals := md.Get("x-apb-session-key"); len(vals) > 0 {
|
|
if userId, err := sessions.ResolveUserId(vals[0]); err == nil {
|
|
return userId
|
|
}
|
|
}
|
|
}
|
|
|
|
defaultId, _ := users.DefaultUserId()
|
|
return defaultId
|
|
}
|