Skip to content

Commit

Permalink
wip: add user_id to handle launchpad admin auth. For now
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou committed Jul 4, 2024
1 parent 0e39649 commit f08bedc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
3 changes: 2 additions & 1 deletion api/launchpad/v1/launchpad.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ message LaunchpadProjectsRequest {
int32 offset = 3;
Sort sort = 4;
SortDirection sort_direction = 5;
// TODO: user authentication (Member of the admin DAO)
// TODO: user authentication (Member of the admin DAO) using a token
string user_address = 6;
}

message LaunchpadProjectsResponse {
Expand Down
43 changes: 21 additions & 22 deletions go/pkg/launchpad/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,28 +294,27 @@ func (s *Launchpad) LaunchpadProjects(ctx context.Context, req *launchpadpb.Laun

// TODO: user authentication (Member of the admin DAO)
// Control if sender is member of the admin DAO
// var isUserAuthorized bool

// userAddress, err := s.authenticate(s.db, req.GetAuthToken())
// if err != nil {
// return nil, errors.Wrap(err, "failed to authenticate")
// }
// err = s.conf.IndexerDB.Raw(`
// SELECT EXISTS (
// SELECT 1
// FROM dao_members dm
// JOIN daos d ON dm.dao_contract_address = d.contract_address
// WHERE dm.member_address = ?
// ) AS dao_exists;
// `,
// userAddress,
// ).Scan(&isUserAuthorized).Error
// if err != nil {
// return errors.Wrap(err, "failed to query database")
// }
// if !isUserAuthorized {
// return errors.New("Unauthorized")
// }
daoAdminAddress := "tori129kpfu7krgumuc38hfyxwfluq7eu06rhr3awcztr3a9cgjjcx5hswlqj8v"
userAddress := req.GetUserAddress()
var isUserAuthorized bool
err = s.conf.IndexerDB.Raw(`
SELECT EXISTS (
SELECT 1
FROM dao_members dm
JOIN daos d ON dm.dao_contract_address = d.contract_address
WHERE d.address = ?
WHERE dm.member_address = ?
) AS dao_exists;
`,
daoAdminAddress,
userAddress,
).Scan(&isUserAuthorized).Error
if err != nil {
return errors.Wrap(err, "failed to query database")
}
if !isUserAuthorized {
return errors.New("Unauthorized")
}

var projects []launchpadpb.LaunchpadProject
orderDirection := ""
Expand Down

0 comments on commit f08bedc

Please sign in to comment.