Login in as other parties via @daml/hub-react’s DamlHubLogin

I created a new party in the Daml Hub console. Now I’d like to login as that party in create-daml-app which uses @daml/hub-react’s DamlHubLogin button. However, that doesn’t actually offer me a choice which party I’m using. Am I missing something here?

1 Like

The login method used by the DamlHubLogin component can be customized by props. By default, (no props) it uses the interactive login that authenticates the user as their default ledger party.

There is another method available that allows a user to supply a parties.json file containing party IDs and their respective tokens, that can be downloaded from Daml Hub directly on the Identities page.

To enable this login method, the documentation here may be helpful, but it essentially amounts to including the withFile and onPartiesLoad={(parties) => {...}} props.

From here, there’s some DIY involved as the library doesn’t assume what you want to do with the list of parties, it merely handles the file reading and parsing. But within the onPartiesLoad handler, the usual approach is to set the list of parties in the parent component’s state, and use it to render a dropdown of options. You can see a decent example in the Marketplace app login: https://github.com/digital-asset/da-marketplace/blob/57833c2ab0c564231d095d2e95d3f66b5a6c185b/ui/src/pages/login/Login.tsx#L225-L256

This also offers the flexibility of doing other stuff with the credentials, for instance the marketplace app caches the list in window.localStorage so that the login list persists across sessions, until the tokens expire

2 Likes

Thanks for the comprehensive answer! I realized I don’t actually need to go down quite that far. All I need is a different email address, sign up using that and I can use the button without any changes and get two parties for testing. But I will absolutely keep your solution at hand, I’m sure I’ll need it in the future.

2 Likes