I have speckle v2 running on a docker. and I have a .netcore app, I try to make it connect to the server to get the account.
var currentAccount = AccountManager.GetAccounts(serverUrl).FirstOrDefault();
var SpeckleGraphClient = new Core.Api.Client(currentAccount);
The Account is always Null.
Welcome back to the community!
I think your code looks a bit weird. When calling
GetAccounts, you don’t need to specify the
url of the server. The result will be an
IEnumerable of all your local accounts. Then you can
ToList() to enumerate them.
If what you are looking for is your “default” account. You can always use the
Here’s an image of how we are getting those on one of the nodes of the Grasshopper Connector.
In your case you are calling
GetAccounts().FirstOrDefault(), which can return null if there is no first nor default to return (meaning, the list may be empty?).
- first ensure that your Speckle Manager app has at least one account properly set up.
- Then, try you code but just remove the input on
GetAccounts(). To be honest, That should have thrown a compiler warning, as the
GetAccounts() method doesn’t take any inputs.
Hope that fixes your problems.
On a side note, if you are looking to build apps that are not exclusively for Desktop computers (where users can have the Speckle Manager installed), I would suggest to look into our Authentication strategies using Tokens or Speckle Apps you can find more info on how that works here:
Thank you for the fast reply.
I think the best approach is via Tokens or Speckle Apps. I will check the examples. Thank you.
I thought so, considering you’re looking into a netcore app, which can virtually run anywhere
We also have a guide to create a Speckle App, but that’s written in Vue (HTML/JS framework), so the code won’t be exactly the same, but the logic and endpoints used will be.
Ping us if you struggle with anything else! And happy hacking!!