✨ Authkit support check user related permission
This commit is contained in:
parent
b4da8ce78b
commit
40a0403521
26
pkg/authkit/auth.go
Normal file
26
pkg/authkit/auth.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package authkit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||||
|
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||||
|
"github.com/samber/lo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EnsureUserPermGranted(nx *nex.Conn, userId, otherId uint, key string, val any) error {
|
||||||
|
conn, err := nx.GetClientGrpcConn(nex.ServiceTypeAuth)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get auth service client: %v", err)
|
||||||
|
}
|
||||||
|
resp, err := proto.NewAuthServiceClient(conn).EnsureUserPermGranted(context.Background(), &proto.CheckUserPermRequest{
|
||||||
|
UserId: uint64(userId),
|
||||||
|
OtherId: uint64(otherId),
|
||||||
|
Key: key,
|
||||||
|
Value: nex.EncodeMap(val),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return lo.Ternary(resp.GetIsValid(), nil, fmt.Errorf("missing permission: %v", key))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user