fix: check auth status

This commit is contained in:
Steven
2023-11-30 21:52:02 +08:00
parent 2437419b7f
commit fff42ebc0d
5 changed files with 405 additions and 396 deletions

View File

@@ -3,16 +3,18 @@ package v2
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
)
func (s *APIV2Service) GetAuthStatus(ctx context.Context, _ *apiv2pb.GetAuthStatusRequest) (*apiv2pb.GetAuthStatusResponse, error) {
ok := true
user, err := getCurrentUser(ctx, s.Store)
if err != nil || user == nil {
ok = false
if err != nil {
return nil, status.Errorf(codes.Unauthenticated, "failed to get current user: %v", err)
}
return &apiv2pb.GetAuthStatusResponse{
Ok: ok,
User: convertUserFromStore(user),
}, nil
}