# UserSession | Stacks.js 1.4.1 Library Reference
Documentation for Stacks.js 1.4.1 Library Reference

Represents an instance of a signed in user for a particular app.

A signed in user has access to two major pieces of information about the user, the user's private key for that app and the location of the user's gaia storage bucket for the app.

A user can be signed in either directly through the interactive sign in process or by directly providing the app private key.

### Hierarchy

- UserSession

## Index

### Constructors

- constructor

### Properties

- appConfig
- store

### Methods

- decryptContent
- encryptContent
- generateAndStoreTransitKey
- getAuthResponseToken
- handlePendingSignIn
- isSignInPending
- isUserSignedIn
- loadUserData
- makeAuthRequest
- signUserOut

## Constructors

### constructor

- new UserSession(options?: { appConfig?: AppConfig ; sessionOptions?: SessionOptions; sessionStore?: SessionDataStore }): UserSession

- - Defined in packages/auth/src/userSession.ts:51

  Creates a UserSession object

  #### Parameters

  - ##### Optional options: { appConfig?: AppConfig ; sessionOptions?: SessionOptions; sessionStore?: SessionDataStore }

    - ##### Optional appConfig?: AppConfig

    - ##### Optional sessionOptions?: SessionOptions

    - ##### Optional sessionStore?: SessionDataStore

  #### Returns UserSession

## Properties

### appConfig

appConfig: AppConfig

- Defined in packages/auth/src/userSession.ts:49

### store

store: SessionDataStore

- Defined in packages/auth/src/userSession.ts:51

## Methods

### decryptContent

- decryptContent(content: string, options?: { privateKey?: string }): Promise<string | Buffer>

- - Defined in packages/auth/src/userSession.ts:395

  Decrypts data encrypted with `encryptContent` with the transit private key.

  #### Parameters

  - ##### content: string

    encrypted content.

  - ##### Optional options: { privateKey?: string }

    - ##### Optional privateKey?: string

      The hex string of the ECDSA private key to use for decryption. If not provided, will use user's appPrivateKey.

  #### Returns Promise<string | Buffer>

  decrypted content.

### encryptContent

- encryptContent(content: string | Buffer, options?: EncryptContentOptions ): Promise<string>

- - Defined in packages/auth/src/userSession.ts:378

  Encrypts the data provided with the app public key.

  #### Parameters

  - ##### content: string | Buffer

    the data to encrypt

  - ##### Optional options: EncryptContentOptions

  #### Returns Promise<string>

  Stringified ciphertext object

### generateAndStoreTransitKey

- generateAndStoreTransitKey(): string

- - Defined in packages/auth/src/userSession.ts:151

  Generates a ECDSA keypair to use as the ephemeral app transit private key and store in the session.

  #### Returns string

  the hex encoded private key

### getAuthResponseToken

- getAuthResponseToken(): string

- - Defined in packages/auth/src/userSession.ts:163

  Retrieve the authentication token from the URL query

  #### Returns string

  the authentication token if it exists otherwise `null`

### handlePendingSignIn

- handlePendingSignIn(authResponseToken?: string): Promise< UserData >

- - Defined in packages/auth/src/userSession.ts:216

  Try to process any pending sign in request by returning a `Promise` that resolves to the user data object if the sign in succeeds.

  #### Parameters

  - ##### authResponseToken: string = ...

    the signed authentication response token

  #### Returns Promise< UserData >

  that resolves to the user data object if successful and rejects if handling the sign in request fails or there was no pending sign in request.

### isSignInPending

- isSignInPending(): boolean

- - Defined in packages/auth/src/userSession.ts:183

  Check if there is a authentication request that hasn't been handled.

  Also checks for a protocol echo reply (which if detected then the page will be automatically redirected after this call).

  #### Returns boolean

  `true` if there is a pending sign in, otherwise `false`

### isUserSignedIn

- isUserSignedIn(): boolean

- - Defined in packages/auth/src/userSession.ts:204

  Check if a user is currently signed in.

  #### Returns boolean

  `true` if the user is signed in, `false` if not.

### loadUserData

- loadUserData(): UserData

- - Defined in packages/auth/src/userSession.ts:361

  Retrieves the user data object. The user's profile is stored in the key Profile.

  #### Returns UserData

  User data object.

### makeAuthRequest

- makeAuthRequest(transitKey?: string, redirectURI?: string, manifestURI?: string, scopes?: string[], appDomain?: string, expiresAt?: number, extraParams?: any): string

- - Defined in packages/auth/src/userSession.ts:114

  Generates an authentication request that can be sent to the Blockstack browser for the user to approve sign in. This authentication request can then be used for sign in by passing it to the [[redirectToSignInWithAuthRequest]] method.

  Note: This method should only be used if you want to use a customized authentication flow. Typically, you'd use [[redirectToSignIn]] which is the default sign in method.

  #### Parameters

  - ##### Optional transitKey: string

    A HEX encoded transit private key.

  - ##### Optional redirectURI: string

    Location to redirect the user to after sign in approval.

  - ##### Optional manifestURI: string

    Location of this app's manifest file.

  - ##### Optional scopes: string[]

    The permissions this app is requesting. The default is `store_write`.

  - ##### Optional appDomain: string

    The origin of the app.

  - ##### expiresAt: number = ...

    The time at which this request is no longer valid.

  - ##### extraParams: any = {}

    Any extra parameters to pass to the authenticator. Use this to pass options that aren't part of the Blockstack authentication specification, but might be supported by special authenticators.

  #### Returns string

  the authentication request

### signUserOut

- signUserOut(redirectURL?: string): void

- - Defined in packages/auth/src/userSession.ts:410

  Sign the user out and optionally redirect to given location.

  #### Parameters

  - ##### Optional redirectURL: string

    Location to redirect user to after sign out. Only used in environments with `window` available

  #### Returns void

Generated using TypeDoc