From 4fb4abda8948df12656765003621073d5d42c4a9 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 22 May 2024 23:21:31 +0800 Subject: [PATCH] :bug: Bug fixes in grpc unable to get avatar and banner url --- pkg/grpc/auth.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pkg/grpc/auth.go b/pkg/grpc/auth.go index 71ecc03..66de9ff 100644 --- a/pkg/grpc/auth.go +++ b/pkg/grpc/auth.go @@ -3,6 +3,7 @@ package grpc import ( "context" "fmt" + "git.solsynth.dev/hydrogen/passport/pkg/grpc/proto" "git.solsynth.dev/hydrogen/passport/pkg/services" jsoniter "github.com/json-iterator/go" @@ -19,21 +20,29 @@ func (v *Server) Authenticate(_ context.Context, in *proto.AuthRequest) (*proto. } else { user := ctx.Account rawPerms, _ := jsoniter.Marshal(perms) + + userinfo := &proto.Userinfo{ + Id: uint64(user.ID), + Name: user.Name, + Nick: user.Nick, + Email: user.GetPrimaryEmail().Content, + Description: &user.Description, + } + + if user.Avatar != nil { + userinfo.Avatar = fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), *user.Avatar) + } + if user.Banner != nil { + userinfo.Banner = fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), *user.Banner) + } + return &proto.AuthReply{ IsValid: true, AccessToken: &atk, RefreshToken: &rtk, Permissions: rawPerms, TicketId: lo.ToPtr(uint64(ctx.Ticket.ID)), - Userinfo: &proto.Userinfo{ - Id: uint64(user.ID), - Name: user.Name, - Nick: user.Nick, - Email: user.GetPrimaryEmail().Content, - Avatar: fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), user.Avatar), - Banner: fmt.Sprintf("%s/api/attachments/%d", viper.GetString("paperclip.endpoint"), user.Banner), - Description: &user.Description, - }, + Userinfo: userinfo, }, nil } }