Creating a UserSession using app private key


The blockstack.js documentation ( mentions that a user can directly sign in by providing the app private key .

Is there an example that demonstrates this?

This would be useful for writing unit tests.

1 Like

I think it refers to the fact that you can create a new UserSession object directly and start using that within your code. Will let @zone117x chime in.

1 Like

If you are just starting out, I would suggest you get an overview of how are Auth works here:

A detailed walk through with code examples here:

And any of our all of our sample code does some form of auth but the easiest is Hello Blockstack here:

1 Like

Thanks @moxiegirl Iā€™m familiar with how the auth process generally works with the blockstack browser.

My question is more to do with how we can create a valid UserSession without having to open a browser. This would especially be usefull for writing automated unit tests.

#5 thanks for clarifying your question. @timstackblock Is our test engineer, he might be best to answer that.


This should be the minimum required code to create a UserSession instance that runs in Node.js, and can perform gaia file operations.

const appConfig = new AppConfig(
  '' /* your app origin */ 
const dataStore = new InstanceDataStore({ 
  userData: {
    appPrivateKey: '8a2c9a65...', /* A user's app private key */
    hubUrl: '' /* A user's gaia hub server */
    /* The rest of the properties can be null */
const userSession = new UserSession({
  appConfig: appConfig,
  sessionStore: dataStore
Support for UserSession in node environment

Thanks! Exactly what I was looking for :slight_smile:

1 Like